首先,我想说的是,我意识到这个问题已经被问了十二遍了,我读了无数的解决方案而没有运气,因此,我再次询问。

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

我正在尝试编译此简单文件(test.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标志,但我不确定我是否知道它们在做什么/如何提供帮助。

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

编辑:一些其他信息。我已经尝试将.framework用于SDL2,但没有做任何更改,目前我正在使用通过编译源代码安装的SDL2。标题位于usr/local/SDL2

最佳答案



您还应该指定SDL库:

g++ test.cpp -lsdl2

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

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

关于c++ - ld:找不到架构符号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27464802/

10-11 15:39