LD:找不到建筑符号

ld: symbol(s) not found for architecture

本文关键字:符号 建筑 找不到 LD      更新时间:2023-10-16

首先,我想说我意识到这个问题已经被问了十几次,而且我读了无数的解决方案,没有任何运气,所以我再问一次。

我正在使用OS X Mavericks 10.9.5,用Sublime 3编写并使用g++终端进行编译

我正在尝试编译这个简单的文件(测试.cpp)

#include <iostream>
#include <SDL2/SDL.h>
int main () {
    if(SDL_Init(SDL_INIT_VIDEO)) {
    std::cout << "I made it this far" << std::endl;
    }
    return 0;
}

编译器行:

g++ test.cpp

这将返回错误:

Undefined symbols for architecture x86_64:
    "_SDL_Init", referenced from:
         _main in test-ebbae4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

因此,我尝试添加许多不同的标志,-m32只会更改结果以抛出Undefined symbols for architecture i386:ld: symbol(s) not found for architecture i386

我已经尝试了不同的-arch变体,但我似乎无法让它工作。 也玩过-l -I标志,但我不确定我知道他们做什么/他们如何提供帮助。

有没有人知道下一步该怎么做?

编辑:一些附加信息。我尝试使用 SDL2 的 .framework,这并没有改变任何东西,目前我使用的是通过编译源代码安装的 SDL2。位于usr/local/SDL2的标头

G++ 测试.cpp

您还应该指定 SDL 库:

G++ test.cpp -LSDL2

如果编译器驱动程序不知道路径,则可能需要包含路径:

g++ test.cpp -L/path/to/the/library -lsdl2