在Ubuntu上使用SDL2_TTF:/usr/bin/ld: 找不到-lSDL2_ttf。

6

我看了几个可能的解决方案,试图修复这个问题,但在使用SDL_ttf和SDL2绘制文本时仍然存在以下问题。

julian@julian-linux:~/Documents/SDL/Font Demo/pt2$ make
g++ texttest.cpp -w -lSDL2 -lSDL2_ttf -LSDL2_image  -o texttest
/usr/bin/ld: cannot find -lSDL2_ttf
collect2: error: ld returned 1 exit status
Makefile:23: recipe for target 'all' failed
make: *** [all] Error 1

我的Makefile如下:

OBJS = texttest.cpp

#CC specifies which compiler we're using
CC = g++

#COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
COMPILER_FLAGS = -w

#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -lSDL2 -lSDL2_ttf -LSDL2_image 

#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = texttest

#This is the target that compiles our executable
all : $(OBJS)
    $(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)

非常感谢提前提供的任何帮助。


3
"cannot find -lSDL2_ttf" 意味着你在链接器库路径中没有 libSDL2_ttf.solibSDL2_ttf.a。可能你没有安装该库的开发包(但是你怎么有头文件呢?),已经损坏了,或者是错误的架构。另外,使用编译器标志 -w 是最糟糕的想法,虽然与问题无关。 - keltar
1个回答

11
我通过运行以下命令解决了这个问题:

sudo apt-get install libsdl2-ttf-dev

以前,我曾试图用以下方法修复它:

sudo apt-get install libsdl-ttf2.0-dev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接