我正在尝试编译 libavcodec 示例。我收到以下错误:
\n\nlol@foldingmachine:~/p/avtest$ g++ main.cpp -o main -lavcodec\nmain.cpp: In function \xe2\x80\x98void audio_decode_example(const char*, const char*)\xe2\x80\x99:\nmain.cpp:57:15: warning: \xe2\x80\x98int avcodec_decode_audio4(AVCodecContext*, AVFrame*, int*, const AVPacket*)\xe2\x80\x99 is deprecated [-Wdeprecated-declarations]\n len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt);\n ^~~~~~~~~~~~~~~~~~~~~\nIn file included from main.cpp:1:0:\n/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:4773:5: note: declared here\n int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,\n ^~~~~~~~~~~~~~~~~~~~~\nmain.cpp:57:73: warning: \xe2\x80\x98int avcodec_decode_audio4(AVCodecContext*, AVFrame*, int*, const AVPacket*)\xe2\x80\x99 is deprecated [-Wdeprecated-declarations]\n len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt);\n ^\nIn file included from main.cpp:1:0:\n/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:4773:5: note: declared here\n int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,\n ^~~~~~~~~~~~~~~~~~~~~\n/tmp/ccbXVtbs.o: In function `audio_decode_example(char …Run Code Online (Sandbox Code Playgroud) 我们正在尝试修改一些现有的C项目,即我们正在尝试从C代码中进行一些C++函数调用.我们尝试将编译器从gcc更改为g ++,但由于不兼容性,存在多个编译错误.我们要做的是在C代码中调用一些C++函数,而不对现有代码进行任何更改.简单地改变编译器似乎没有做到这一点.因此,我们试过以下:
#include <stdio.h>
extern "C"
{
int func(int new ) {
printf("in new func()\n");
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用命令编译它
g ++ -c hello.c -o hello
我们得到以下错误
hello.c:9: error:expected ‘,’ or ‘...’ before ‘new’.
Run Code Online (Sandbox Code Playgroud)
现在我们知道new是c ++关键字.如前所述,我们试图不对现有的C代码进行任何修改.有什么建议 ?
这些不是唯一的错误.还有与结构声明相关的其他错误.
attr.c:75:错误:在'.'之前预期的primary-expression 代币
在attr.c,第75行是
static post_op_attr error_attr = {.attributes_follow = FALSE};
问题是在代码中还有其他C样式的结构声明和初始化,所以即使我们重命名变量名,我们仍然需要修改C程序的其他部分.因此,我们正在寻找一种方法来在不修改现有C代码的情况下向C代码添加C++函数调用.
我似乎无法打开CD托盘.它突然出现了'extern C'的错误,extern意味着什么呢?
谢谢!这是图像! C++打开CD托盘时出错
我有一个小问题。
我认为使用 usingextern "C"会将 C 代码直接转换为 C++ 代码。
#ifdef __cplusplus
extern "C" {
#endif
ENUM_J1939_STATUS_CODES CAN_Send_Message(uint32_t ID, uint8_t data[], uint8_t delay);
ENUM_J1939_STATUS_CODES CAN_Send_Request(uint32_t ID, uint8_t PGN[], uint8_t delay);
bool CAN_Read_Message(uint32_t *ID, uint8_t data[]);
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)
但是当我QSerialPort在这里上课时
#ifdef __cplusplus
extern "C" {
#endif
#include <QSerialPort>
ENUM_J1939_STATUS_CODES CAN_Send_Message(uint32_t ID, uint8_t data[], uint8_t delay);
ENUM_J1939_STATUS_CODES CAN_Send_Request(uint32_t ID, uint8_t PGN[], uint8_t delay);
bool CAN_Read_Message(uint32_t *ID, uint8_t data[]);
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)
然后我得到了 500 个关于数据类型、命名空间和 C 没有的所有类型的 C++ 关键字的错误。 …
我需要使用mbed api但仅限于使用C.我如何在ac文件中使用例如SPI类.从在线查看使用C++类,您应该在C++中创建一个包装器函数,但正如我所说的,我不能使用C++,这是他们的另一种解决方法吗?