【发布时间】:2015-12-23 18:09:58
【问题描述】:
我正在尝试使用 gcc 编译从 github 获取的内容:
users-MBP:Chip-8-Emulator user$ gcc -o chip8 chip8.c
Undefined symbols for architecture x86_64:
"_SDL_Delay", referenced from:
_chip8_draw in chip8-bc89fc.o
"_SDL_Flip", referenced from:
_chip8_draw in chip8-bc89fc.o
"_SDL_GetKeyState", referenced from:
_chip8_execute in chip8-bc89fc.o
_chip8_prec in chip8-bc89fc.o
"_SDL_GetVideoSurface", referenced from:
_chip8_draw in chip8-bc89fc.o
"_SDL_Init", referenced from:
_chip8_prepare in chip8-bc89fc.o
"_SDL_LockSurface", referenced from:
_chip8_draw in chip8-bc89fc.o
"_SDL_PollEvent", referenced from:
_chip8_prepare in chip8-bc89fc.o
_chip8_prec in chip8-bc89fc.o
"_SDL_SetVideoMode", referenced from:
_chip8_prepare in chip8-bc89fc.o
"_SDL_UnlockSurface", referenced from:
_chip8_draw in chip8-bc89fc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
在这种情况下,错误似乎是 SDL 库的问题,但我在编译的其他几个小项目中也遇到了完全相同的问题。在编译之前,我安装了 SDL 库并检查了它们是否存在:
users-MBP:Chip-8-Emulator user$ ls /usr/local/lib/
...
libSDL-1.2.0.dylib
libSDL.a
libSDL.dylib
libSDLmain.a
...
经过大量谷歌搜索后,似乎我不是唯一遇到此问题的人,而且我找不到有效的解决方案。似乎osx 在默认链接器路径中不包含/use/local/lib。
我该如何解决这个问题(欢迎永久解决方案)?
编辑
根据用户 Alex 的建议,我尝试使用 $ gcc -o chip8 -L/usr/local/lib chip8.c。错误和输出与上述相同。
【问题讨论】:
-
您需要将
-lSDL添加到您的构建命令中
标签: c macos linker libraries undefined-symbol