C++: weird error "expected initializer before extern" in library SDL_image.h

Magnus picture Magnus · Jul 29, 2011 · Viewed 13.4k times · Source

I'm currently trying to make a simple game with SDL and Box2D. Unfortunately, the code I added to make the character shoot proyectiles is so buggy I can't even begin to count the errors. To deal with this I added some code to show some debug info in the game. Unfortunately, after dealing with all the errors a weird error that didn't appear before popped up:

/usr/include/SDL/SDL_image.h|34|error: expected initializer before ‘extern’|
||=== Build finished: 1 errors, 0 warnings ===|

The code in SDL_image.h that causes this is:

/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif

I have no idea what causes this error message to appear, or how to solve this. There are no error messages on my code. I don't think there's anything wrong with the library because other game I did compiles just file. This is the only error that pops up.

Answer

Mike Seymour picture Mike Seymour · Jul 29, 2011

Have a look at the end of the header files that are included before this one. My guess is that there's a missing ; after a class definition.