我正在关注 this尝试使用一些 SDL 扩展库的 SDL 教程。我的代码与 theirs 相同但我仍然无法制作
文件,这让我相信问题出在我的makefile
中,它看起来像这样:
CXX = g++
# Update these paths to match your installation
# You may also need to update the linker option rpath, which sets where to look for
# the SDL2 libraries at runtime to match your install
SDL_LIB = -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image
SDL_INCLUDE = -I/usr/local/include
# You may need to change -std=c++11 to -std=c++0x if your compiler is a bit older
CXXFLAGS = -Wall -c -std=c++11 $(SDL_INCLUDE)
LDFLAGS = $(SDL_LIB)
EXE = SDL_Lesson3
all: $(EXE)
$(EXE): main.o
$(CXX) $< $(LDFLAGS) -o $@
main.o: main.cpp
$(CXX) $(CXXFLAGS) $< -o $@
clean:
rm *.o && rm $(EXE)
那个 makefile
对于前面的例子工作得很好。此示例中唯一发生变化的是第 5 行,我根据教程在其中添加了 -lSDL2_image
。当我尝试 make
文件时,我得到以下回溯:
rony@comet:~/Documents/cpp/helloworld/lesson3$ make
g++ main.o -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image -o SDL_Lesson3
/usr/bin/ld: cannot find : No such file or directory
collect2: error: ld returned 1 exit status
make: *** [SDL_Lesson3] Error 1
我的 makefile 有错误吗?我没有正确安装库吗?
最佳答案
问题是这个流氓逗号:
SDL_LIB = -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image
^
导致链接器在名称为空的不存在目录以及 /usr/local/lib
中查找库。删除逗号应该可以解决它。
关于c++ -/usr/bin/ld : cannot find : No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20616961/