I answer this question, trying to cover this question, which could be considered in a more detailed answer, to help the questioner or other persons who visited this page.
Error: "expected" ("before a string constant"
As mentioned in another answer of your question, extern "C" not valid C (it is valid only in C ++). You can remove it if you use only pure C.
However, if you (or someone else) have mixed C and C ++ source files, you can use the __cplusplus macro. The __cplusplus macro will be defined for any compilation unit that runs through the C ++ compiler. This usually means that the .cpp files and any files are included in this .cpp file.
Thus, the same .h (or .hh or .hpp or what-have-you) can be interpreted as C or C ++ at different times if different compilation units belong to them. If you want the prototypes in the .h file to refer to C symbol names, they must have extern "C" when interpreting C ++, and they must not have extern "C" when interpreting C (as in your case you got an error! )
#ifdef __cplusplus extern "C" { #endif
Note. All extern "C" really affect communication. C ++ functions have distorted names during compilation. This makes overload possible. The function name is changed based on the types and number of parameters, so two functions with the same name will have different symbol names.
If you include a header for code that has a C link (for example, code that was compiled by the C compiler), then you must extern "C" header so you can link to the library. ( Otherwise, your linker would be looking for functions with names like _Z1hic when you were looking for void h(int, char) ).
abhiarora
source share