我仍然在努力编译C控制台应用程序,编译过程仍然失败并出现以下错误:
"Main.c", line 51: error #2040: expected an identifier
extern "C" void TreatReceivedSignal( int NoSignal ) ;
^
1 error detected in the compilation of "Main.c".
gmake: *** [Main.o] Error 2
下面是C代码上extern方法的声明:
extern "C" void TreatReceivedSignal( int NoSignal ) ;
我正在使用HP-UX aCC编译器[HP C / aC ++ B3910B A.06.26],我也打开了编译标志-Ae以启用C99支持。 似乎编译器无法将'extern“C”'识别为C保留字,可能需要设置其他一些编译标志。 请问有什么可以解决这类问题吗? 非常感谢你提前。 此致
答案 0 :(得分:15)
extern "C"
构造是特定于C ++的构造,它不能在C中使用。编译器将源文件视为C源文件,因为它具有扩展名.c
。
最常见的事情是使用预处理器有条件地为C ++编译添加它:
#ifdef __cplusplus
extern "C" {
#endif
/* Standard C prototypes */
#ifdef __cplusplus
}
#endif