c++ - 在 OSX 上安装 SDL

标签 c++ c macos gcc sdl

我下载了 SDL2-2.0.3。我运行了 ./configure && make && make install

我也尝试过 brew install SDL2

这是我的main.c

//Using SDL and standard IO
#include <SDL2/SDL.h>
#include <stdio.h>
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

int main( int argc, char* args[] ) {
 SDL_Window* window = NULL;
 SDL_Surface* screenSurface = NULL;

 if (SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
   printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
 }
}

当我运行它时

~:.make main
gcc     main.c   -o main
Undefined symbols for architecture x86_64:
  "_SDL_GetError", referenced from:
      _main in main-d5699d.o
  "_SDL_Init", referenced from:
      _main in main-d5699d.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1
~:.

如何安装?

最佳答案

您未能链接到 libSDL2.{a,dylib}

你想要:

gcc -o main main.c -lSDL2

或者也许:

gcc -o main main.c -L/usr/local/lib -lSDL2

关于c++ - 在 OSX 上安装 SDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33225603/

相关文章:

c - 使用 nftw 时如何避免使用全局变量

c++按类型大小而不是类型声明变量

c++ - SDL 混音器声音不播放

c++ - 重建字符串删除标点符号的问题

c++ - ClassFactory 自动添加到 ClassTypeFactory

c - 使用scanf读取带空格的字符串?

mysql - 从终端读取数据并插入MySQL

c++ - Mac/iOS收不到UDP广播包,但可以发送UDP广播包

ruby - mini_magick gem 不适用于我的 ImageMagick 安装

Swift - NSShadow 上的 shadowOpacity 在哪里?