We have an assignment to compile a file with SDL library linked. The file itself shouldn't contain any errors since almost everyone managed to compile it. I've installed SDL 1.2 on Ubuntu 12.04 with the following commands:
sudo apt-get install libsdl1.2-dev
sudo apt-get install libsdl-image1.2-dev
sudo apt-get install libsdl-mixer1.2-dev
sudo apt-get install libsdl-ttf2.0-dev
I'm compiling it with the following command:
gcc -o sdl_introduction sdl_introduction.c `sdl-config --cflags --libs`
I'm using with gcc 4.6.3
and I'm getting this error:
/usr/local/lib/libSDL.so: undefined reference to `_XGetRequest'
collect2: ld returned 1 exit status
What could cause the problem?
I have faced the same problem as you, it is caused by the SDL library needing other libraries to link with on ubuntu(or linux generally)
I recommend copiling it with :
gcc -o sdl_introduction sdl_introduction.c -lX11 -pthread `sdl-config --cflags --libs`
Notice the added -lX11 and -pthread.
EDIT:
My bad I forgot that you must add -lX11 and -pthread after the other flags. Resulting in:
gcc -o sdl_introduction sdl_introduction.c `sdl-config --cflags --libs` -lX11 -pthread
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.