gpt4 book ai didi

gcc - Ubuntu 11.10 : GCC/G++ won't link libraries

转载 作者:太空宇宙 更新时间:2023-11-03 16:45:45 25 4
gpt4 key购买 nike

我去编译我的一个项目,它使用了 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-config --libs pkg-config gtk+-2.0 --libs pkg-config openal --libs -lalut -lSDL_ttf

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

#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 选项。也许尝试将 sdl-config --libs --cflags 移动到命令的末尾?即对于您的测试程序:

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

关于gcc - Ubuntu 11.10 : GCC/G++ won't link libraries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8498899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com