Ubuntu 11.10:GCC/G++;韩元';t链接库

Ubuntu 11.10:GCC/G++;韩元';t链接库,gcc,ubuntu,linker,g++,sdl,Gcc,Ubuntu,Linker,G++,Sdl,我去编译我的一个项目,它使用SDL、SDL_ttf、OpenAL和GTK。所有输出错误如下所示: TxtFunc.cpp:(.text+0x61): undefined reference to `TTF_OpenFont' TxtFunc.cpp:(.text+0x8c): undefined reference to `TTF_RenderText_Solid' TxtFunc.cpp:(.text+0xf6): undefined reference to `SDL_UpperBlit'

我去编译我的一个项目,它使用SDL、SDL_ttf、OpenAL和GTK。所有输出错误如下所示:

TxtFunc.cpp:(.text+0x61): undefined reference to `TTF_OpenFont'
TxtFunc.cpp:(.text+0x8c): undefined reference to `TTF_RenderText_Solid'
TxtFunc.cpp:(.text+0xf6): undefined reference to `SDL_UpperBlit'
TxtFunc.cpp:(.text+0x108): undefined reference to `TTF_CloseFont'
TxtFunc.cpp:(.text+0x114): undefined reference to `SDL_FreeSurface'
每次图书馆电话。我使用以下链接选项进行编译:

sdl配置--libs
pkg配置gtk+-2.0--libs
pkg配置openal--libs
-lalut-lSDL\u ttf

我已经安装了所有这些软件包,并且没有“未找到文件”错误。只是很多未定义的引用。。。这没有意义,所以我写了一个快速测试应用程序:

#include "SDL/SDL.h"

int main()
{
    SDL_Init(SDL_INIT_VIDEO);
    return 0;
}
然后像这样编译:

g++ `sdl-config --libs --cflags` -o sdl-test ./sdl-test.cpp
我甚至尝试直接链接到“/usr/lib/libSDL-1.2.so.0”或“/usr/lib/libSDL.a”

所有这些选项最终都具有相同的输出:

/tmp/cc05XT8U.o: In function `main':
sdl-test.cpp:(.text+0xa): undefined reference to `SDL_Init'
collect2: ld returned 1 exit status

有人有什么想法吗?

一般来说,在命令行中使用符号的文件后面需要有-l选项。也许可以尝试将
sdlconfig--libs--cflags
移动到命令的末尾?i、 e.对于您的测试计划:

g++ -o sdl-test ./sdl-test.cpp `sdl-config --libs --cflags`

如果您使用SDL_ttf,您需要

g++ main.cpp -o sdl-test `sdl-config --libs --cflags` -lSDL_ttf

哪一个pillock想到了改变编译器,使其现在依赖于命令行中选项的顺序


好吧,这也解决了我的问题,只是在我的Makefile中($OBJS)之后移动了($CFLAGS),我所有对SDL libs的未知引用的链接问题都消失了>。OP可能还想阅读关于为什么命令行上的库顺序很重要的解释:就是这样!谢谢我想我从来都不知道它的重要性,只是碰巧总是写对了!职业俄罗斯人:是的,这很有道理!再次感谢各位!