无法使用在 Ubuntu 上链接的 SDL 库编译文件

标签 c linker sdl

我们有一项任务是编译链接有 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/

相关文章:

C - 打印出现次数最多的字符串

c++ - 为什么我在打印这个结构指针时出错?

c - 用/替换许多文件的脚本是什么样的?

c++ - 行为根据它所链接的类而改变的程序

c++ - 为静态链接构建 Boost (MinGW)

c++ - 将 SDL2 与 Xcode 一起使用时出现 AddInstanceForFactory 和 HALC_ShellDriverPlugIn 错误?

C: 在 Raspberry Pi 上写入数组指针时出现段错误

c++ - 使用 clang 显式 C++ 模板实例化

c++ - 如何在VST 2.4中创建子窗口?

c - SDL2 通过操作像素和 SDL_UpdateTexture() 弄乱了图像