I'm following this SDL tutorial to try and make use of some SDL extension libraries. My code is identical to theirs but I am still unable to make
the file which leads me to believe the problem is in my makefile
which looks like this:
我正在学习SDL教程,尝试使用一些SDL扩展库。我的代码和他们的代码是一样的,但是我仍然不能生成文件,这让我相信问题出在我的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)
That makefile
worked fine for previous examples. The only thing that has changed in this example is line 5 where I added -lSDL2_image
as per the tutorial. When I try make
the file I get the following traceback:
该makefile对前面的示例工作得很好。在这个例子中唯一改变的是第5行,我按照教程添加了-lSDL2_image。当我尝试制作这个文件时,我得到了如下的回溯:
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
Is there an error with my makefile? Have I not installed the library correctly?
我的makefile有错误吗?我没有正确安装库吗?
1 个解决方案
#1
6
The problem is this rogue comma:
问题是这个流氓逗号:
SDL_LIB = -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image
^
causing the linker to look for libraries in a non-existent directory with an empty name, as well as /usr/local/lib
. Removing the comma should fix it.
导致链接器在一个不存在的、名称为空的目录中查找库,以及/usr/local/lib删除逗号应该会修复它。
#1
6
The problem is this rogue comma:
问题是这个流氓逗号:
SDL_LIB = -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image
^
causing the linker to look for libraries in a non-existent directory with an empty name, as well as /usr/local/lib
. Removing the comma should fix it.
导致链接器在一个不存在的、名称为空的目录中查找库,以及/usr/local/lib删除逗号应该会修复它。