12

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.

Magnus
  • 514
  • 2
  • 7
  • 19
  • 1
    The error message say "before extern" -- the ifdef is *not* what is before, so you need to show us the line of code before that – Soren Jul 29 '11 at 17:06

1 Answers1

53

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.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
  • 2
    +1, but I'm guessing it's a global variable declaration, not a class declaration. With g++ 4.3.4, the code `int x extern int y;` gives the same error, whereas `class X{} extern int y;` gives a different error. – Adam Rosenfield Jul 29 '11 at 18:06
  • 3
    Yup, there was a missing semi-colon after a function. Thanks! – Magnus Jul 29 '11 at 20:40
  • 3
    OMG MAN. I LOVE YOU! I was for more than an hour looking for my error and finally you saved me. There was a missing ; on the last function of my header file. Thanks a lot! – George Jul 02 '15 at 21:48
  • there it is, missing ; !! – hounded Sep 28 '19 at 04:11