Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extern "C" error #2040: expected an identifier

Tags:

c

hp-ux

acc

I still struggling to compile a C console application, the compiling procedure still failing with the error below:

"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

below the declaration of the extern method on the C code :

extern "C" void TreatReceivedSignal( int NoSignal ) ;

I am using HP-UX aCC compiler [HP C/aC++ B3910B A.06.26], also I switched on the compilation flag -Ae to enable C99 support. Seems that the compiler cannot recognize the 'extern "C"' as C reserved word, may some other compilation flag need to be set. Any idea please that can solve this kind of issue? Thank you very much in advance. Regards

like image 562
jamel Avatar asked Apr 24 '13 13:04

jamel


1 Answers

The extern "C" construct is a C++ specific thing, it can't be used in C. And the compiler treats your source file as a C source file since it has the extension .c.

The most common thing to do is to use the preprocessor to conditionally add this for C++ compilations:

#ifdef __cplusplus
extern "C" {
#endif

/* Standard C prototypes */

#ifdef __cplusplus
}
#endif
like image 117
Some programmer dude Avatar answered Nov 14 '22 08:11

Some programmer dude