c++ -/usr/bin/ld : cannot find : No such file or directory

标签 c++ makefile sdl

我正在关注 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/

相关文章:

c++ - 用于 C++ 的 Eclipse 自动完成迭代器

c++ - 确定 QImage 的哪些像素在使用 QPainter 绘画时发生了变化

c++ - 修改 Makefile 添加 GSL 库

makefile - 如何管理C头文件依赖?

c++ - 让 SDL_ttf 与 SDL2 配合使用

c++ - 为回收站中的文件获取 IPropertySetStorage

c++ - LLVM 在运行时获取声明函数的参数值

C - Makefile 在头文件更改后编译,但更改不生效

c++ - 如何获得 GLuint 纹理的宽度?

c++ - SDL_PollEvent 深入