我用 C 语言编写了一个简单的 Chip-8 模拟器(主要是从 this 获得灵感;说实话,只是用 C 语言重写了它)。它使用 SDL 2.0,我肯定已经安装了。
当我尝试编译文件( gcc main.c chip8.c -o chip8
)时,我收到了一堆错误:
Undefined symbols for architecture x86_64:
"_SDL_CreateRenderer", referenced from:
_main in main-638d2a.o
"_SDL_CreateTexture", referenced from:
_main in main-638d2a.o
"_SDL_CreateWindow", referenced from:
_main in main-638d2a.o
"_SDL_GetError", referenced from:
_main in main-638d2a.o
"_SDL_Init", referenced from:
_main in main-638d2a.o
"_SDL_PollEvent", referenced from:
_main in main-638d2a.o
"_SDL_RenderClear", referenced from:
_main in main-638d2a.o
"_SDL_RenderCopy", referenced from:
_main in main-638d2a.o
"_SDL_RenderPresent", referenced from:
_main in main-638d2a.o
"_SDL_RenderSetLogicalSize", referenced from:
_main in main-638d2a.o
"_SDL_UpdateTexture", referenced from:
_main in main-638d2a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我非常确定我使用了正确的 #include ( #include "SDL2/SDL.h"
)。这是我的项目结构:
chip-8
—— main.c
–– chip8.c
–– chip8.h
–– INVADERS (rom file)
为什么链接器不能使用这个?是否需要任何其他编译器标志?
最佳答案
Why doesn't the linker work with this? Are any other compiler flags required?
是的,您需要告诉链接器要链接哪些库,例如:
-lSDL2
关于c - 为什么 gcc 不链接 SDL 2.0 C 项目? (苹果系统),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60046159/