首页 > 解决方案 > 启用在 macbook 上编译 sdl 1.2 项目

问题描述

我试试这个:

g++ -Wall affichage.c -o game -D_REENTRANT -I/usr/local/Cellar/sdl/1.2.15_1/SDL

但我有这个错误:

Undefined symbols for architecture x86_64:
  "_SDL_EnableKeyRepeat", referenced from:
      chargement_objets(img*, img*) in affichage-50cd48.o
  "_SDL_Flip", referenced from:
      affiche_menu(img, img) in affichage-50cd48.o
      _SDL_main in affichage-50cd48.o


gcc Version : 
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

sdl 安装在:/usr/local/Cellar/sdl/1.2.15_1

Mac OS 卡特琳娜

标签: cmacosgcccompilationsdl

解决方案


未定义符号错误发生在链接时。因此,就像将标头查找路径指定为 一样-I/usr/local/Cellar/sdl/1.2.15_1/SDL,这有助于编译时,将库搜索路径指定为-L/usr/local/Cellar/sdl/1.2.15_1/SDL/lib或类似的指向正确路径的东西。您可能还需要添加诸如-lSDL指定您使用的函数所在的库之类的内容。请注意, -l SDL表示针对 lib SDL .a的链接


推荐阅读