Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

sdl

sdl-image

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.

like image 345
Magnus Avatar asked Jul 29 '11 16:07

Magnus


People also ask

How to install SDL_image library?

You need to install SDL_image library like mentioned in the other answers, if you are on a Debian based systems you can simply install with the following command: In the third tutorial of lazyfoo is completely explained. Basically, you must add "-lSDL_image" to the compilation line.

What is SDL in C++ with examples?

SDL library in C/C++ with examples. SDL is Simple DirectMedia Layer.It is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D.It can be used to make animations and video games.

Is the sdl2_image file shipped with SDL2?

It's not shipped with SDL. For those who are using SDL2, the file name has changed to "SDL2_image.h". See documentation: wiki.libsdl.org/MigrationGuide#line-435


1 Answers

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.

like image 177
Mike Seymour Avatar answered Oct 19 '22 13:10

Mike Seymour