SDL2_gfx:架构x86_64(Mac)的未定义符号

时间:2018-05-28 13:30:35

标签: c++ sdl-2

我一直在尝试使用SDL2_gfx库学习SDL2,但是我在编写示例程序时遇到了困难。我跑的时候:

g++ -c -Wall main.cpp -o main.o
g++ main.o -L/usr/local/lib -lSDL2 -framework SDL2 -o main
Undefined symbols for architecture x86_64:
  "_boxColor", referenced from:
      _main in main.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

我也尝试了很多不同的东西,例如使用sdl2-config --libs --cflags,但这会产生同样的错误。当只使用SDL2函数时,编译很好,这是问题的SDL2_gfx函数。我对C ++比较陌生,但是当我意外地使用boxColor函数发出语法错误时,编译器就抓住了它,所以我认为它正在我的程序中正确包含。任何帮助将不胜感激。

这也是我的代码:

#include <SDL2/SDL.h>
#include <SDL2/SDL2_gfxPrimitives.h>

#define WIDTH 640
#define HEIGHT 480

int main(int argc, char* argv[])
{

   if (SDL_Init(SDL_INIT_VIDEO))
   {
      printf ("SDL_Init Error: %s", SDL_GetError());
      return 1;
   }

   SDL_Window *window = SDL_CreateWindow("SDL2_gfx test", 100, 100, WIDTH, HEIGHT, SDL_WINDOW_OPENGL);
   if (window == NULL)
   {
      printf ("SDL_CreateWindow Error: %s", SDL_GetError());
      SDL_Quit();
      return 2;
   }

   SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
   if (renderer == NULL)
   {
      SDL_DestroyWindow(window);
      printf ("SDL_CreateRenderer Error: %s", SDL_GetError());
      SDL_Quit();
      return 3;
   }

   SDL_Event e;

   int quit = 0;
   while (!quit)
   {
      if (SDL_PollEvent(&e))
      {
         if (e.type == SDL_QUIT)
            quit = 1;
      }
      SDL_SetRenderDrawColor(renderer, 0, 0, 0xFF, 0xFF);
      boxColor(renderer, WIDTH / 4, HEIGHT / 4, 3 * WIDTH / 4, 3* HEIGHT / 4, 0xFF0000FF);
      SDL_RenderClear(renderer);
      SDL_RenderPresent(renderer);
      SDL_Delay(10);
   }

   SDL_DestroyRenderer(renderer);
   SDL_DestroyWindow(window);
   SDL_Quit();
   return 0;
}

0 个答案:

没有答案