/ usr/bin/ld:找不到:没有这样的文件或目录

 天王2502871933 发布于 2023-02-10 09:55

我正在按照这个 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有错误吗?我没有正确安装库吗?

1 个回答
  • 问题是这个流氓逗号:

    SDL_LIB = -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image
                                                               ^
    

    导致链接器在具有空名称的不存在的目录中查找库,以及/usr/local/lib.删除逗号应修复它.

    2023-02-10 10:00 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有