为什么 gcc link 不是 SDL 2.0 C 项目? (苹果系统)

Why doesn't gcc link an SDL 2.0 C project? (macOS)

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

是的,您需要告诉 linker link 反对哪些库,例如:

-lSDL2

How to use SDL with gcc?