solution:SDL_image.h:undefined&n…

gcc error:
----------------------------------------------------------------------
LoadPNG.c:(.text+0x45): undefined reference to `IMG_Load'
collect2: ld returned 1 exit status
----------------------------------------------------------------------
egg pain for an hour....

before:
I compile like this:
>>gcc -Wall hello.c -o hello `sdl-config --cflags --libs`
if I do not use the extension sdl , everything is fine,
however,when I try to load png jpg tif ... pictures , I have to use the extension sdl modules,the compile error appears like what I had shown in the beginning of this article.
I search Internet,I found the same problem:
http://www.elfnet.org/2011/11/30/sdl-undefined-reference-img_load-solved/
the solution is:
compile like following:
>>gcc -Wall hello.c -o hello `sdl-config --cflags --libs` -lSDL_image
but you should not compile like this:
>>gcc -Wall hello.c -o hello -lSDL -lSDL_image
the gcc donot know where is the include file
you can try like following
>>gcc -Wall hello.c -o hello -I/usr/include/SDL -lSDL -lSDL_image
then whatever extension you add ,just add -lSDL_XXXX ,the world comes back again!

你可能感兴趣的:(solution:SDL_image.h:undefined&n…)