我正在按照这个 SDL教程尝试使用一些SDL扩展库.我的代码与他们的代码相同,但我仍然无法找到make
导致我相信问题出现在我的文件中的文件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
.删除逗号应修复它.