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

标签 c gcc sdl-2

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

相关文章:

c++ - 如何通过反汇编从 C++ 函数中获取 "lea"指令?

c - 来自 "Linux kernel programming"的源代码示例

c - Sqlite3 - 试图在回调中填充结构

gcc __attribute__ 声明和定义分离

php - SplFixedArray 是在幕后用 C/C++ 实现的吗?

c++ - std::string 复制构造函数在 GCC 4.1.2 中不是很深?

linux - 如何使g++正确使用我自己的glibc构建的 header ?

c++ - 为什么我的 SDL/C++ 图像消失了?

c++ - 不同类型的Typedef重定义(Emscripten SDL2+OpenGL)

c - 运行 SDL 程序