What's extern "C"?

Started by
6 comments, last by lincsimp 18 years, 8 months ago
Hey My prog has extern "C" in one of the libs. When I try to compile it I get: zlib/zlib.h:37: error: syntax error before string constant zlib/zlib.h:94: error: syntax error before "alloc_func" zlib/zlib.h:94: warning: no semicolon at end of struct or union zlib/zlib.h:101: error: syntax error before '}' token zlib/zlib.h:101: warning: data definition has no type or storage class zlib/zlib.h:103: error: syntax error before '*' token zlib/zlib.h:103: warning: data definition has no type or storage class zlib/zlib.h:217: error: syntax error before "strm" zlib/zlib.h:299: error: syntax error before "strm" zlib/zlib.h:334: error: syntax error before "strm" zlib/zlib.h:433: error: syntax error before "strm" zlib/zlib.h:507: error: syntax error before "strm" zlib/zlib.h:544: error: syntax error before "dest" zlib/zlib.h:562: error: syntax error before "strm" zlib/zlib.h:573: error: syntax error before "strm" zlib/zlib.h:594: error: syntax error before "strm" zlib/zlib.h:603: error: syntax error before "strm" zlib/zlib.h:662: error: syntax error before "strm" zlib/zlib.h:681: error: syntax error before "strm" zlib/zlib.h:696: error: syntax error before "dest" zlib/zlib.h:712: error: syntax error before "strm" zlib/zlib.h:747: error: syntax error before '*' token zlib/zlib.h:816: error: syntax error before '*' token zlib/zlib.h:1160: error: syntax error before "strm" zlib/zlib.h:1162: error: syntax error before "strm" zlib/zlib.h:1164: error: syntax error before "strm" zlib/zlib.h:1168: error: syntax error before "strm" zlib/zlib.h:1170: error: syntax error before '*' token zlib/zlib.h:1193: error: syntax error before "z" zlib/zlib.h:1197: error: syntax error before '}' token What am I doing wrong?? cheers
Advertisement
This is very likely to be a problem with your own source code not the library. If you paste your code here we can help [smile].

ace
Thanks. It's part of zlib.h
Quote:Original post by lincsimp
What's extern "C"?


It tells a C++ compiler to use C linking conventions, it does things like suppress name mangling etc.

What compiler are using and how are you using it.

[Edited by - snk_kid on August 15, 2005 8:02:24 AM]
Thanks! I'm using mingw.. Why would it be cauing an error though?

cheers
Quote:Original post by lincsimp
Thanks! I'm using mingw.. Why would it be cauing an error though?

cheers


Well i know you can get the error message: error: syntax error before string constant when you have extern "C" statement in C code compiled under a C compiler but looking at zlib.h header that shouldn't happen (if i'm looking at the wright one) as it does the idiomatic:

#ifdef __cplusplusextern "C" {#endif...#ifdef __cplusplus};#endif


which checks to see if the macro __cplusplus is defined (predefined macro in standard C++) this allows you to determine if a compiler is compiling in C++ mode, if it is then the extern "C" statement is used if not then its not added.

So if your compiling this in C mode then __cplusplus should not be defined (and therefore not have an extern "C" statement).

[Edited by - snk_kid on August 15, 2005 9:35:10 AM]
Quote:Original post by lincsimp
zlib/zlib.h:37: error: syntax error before string constant


Sanity check: Check to make sure that any header you include before zlib.h doesn't have any syntax errors. The compiler may not be able to accurately locate the source of some sorts of errors, and so the error may "flow" into the next included file. Forgetting the semicolon at the end of a class declaration, for example.
thanks snk_kid!!

This topic is closed to new replies.

Advertisement