我们有一项任务是编译链接有 SDL 库的文件。文件本身不应包含任何错误,因为几乎每个人都设法编译了它。我已经使用以下命令在 Ubuntu 12.04 上安装了 SDL 1.2:
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
我正在使用以下命令编译它:
gcc -o sdl_introduction sdl_introduction.c `sdl-config --cflags --libs`
我正在使用 gcc 4.6.3
我收到了这个错误:
/usr/local/lib/libSDL.so: undefined reference to `_XGetRequest'
collect2: ld returned 1 exit status
可能导致问题的原因是什么?
最佳答案
我遇到了和你一样的问题,这是由于SDL库需要在ubuntu(或一般的linux)上链接其他库造成的
我建议用 :
gcc -o sdl_introduction sdl_introduction.c -lX11 -pthread `sdl-config --cflags --libs`
注意添加的 -lX11 和 -pthread。
编辑:
糟糕的是我忘记了您必须在其他标志之后添加 -lX11 和 -pthread。 结果:
gcc -o sdl_introduction sdl_introduction.c `sdl-config --cflags --libs` -lX11 -pthread
关于无法使用在 Ubuntu 上链接的 SDL 库编译文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20303031/