gpt4 book ai didi

c - 为什么 gcc 不链接 SDL 2.0 C 项目? (苹果系统)

转载 作者:行者123 更新时间:2023-11-30 16:06:08 25 4
gpt4 key购买 nike

我用 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

参见How to use SDL with gcc?

关于c - 为什么 gcc 不链接 SDL 2.0 C 项目? (苹果系统),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60046159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com