grimfang4 / sdl-gpu

A library for high-performance, modern 2D graphics with SDL written in C.
MIT License
1.18k stars 123 forks source link

Building from source fails with `Undefined symbols for architecture x86_64` on macOS 10.15.7 #233

Open ynfle opened 2 years ago

ynfle commented 2 years ago
[ 34%] Linking C shared library ../SDL_gpu/lib/SDL2_gpu.framework/SDL2_gpu
Undefined symbols for architecture x86_64:
  "_SDL_GL_SwapBuffers", referenced from:
      _Flip in renderer_OpenGL_1_BASE.c.o
      _Flip in renderer_OpenGL_1.c.o
      _Flip in renderer_OpenGL_2.c.o
      _Flip in renderer_OpenGL_3.c.o
      _Flip in renderer_OpenGL_4.c.o
  "_SDL_GetVideoSurface", referenced from:
      _GPU_GetFullscreen in SDL_gpu.c.o
      _SetFullscreen in renderer_OpenGL_1_BASE.c.o
      _get_window_id in renderer_OpenGL_1_BASE.c.o
      _get_window in renderer_OpenGL_1_BASE.c.o
      _resize_window in renderer_OpenGL_1_BASE.c.o
      _SetFullscreen in renderer_OpenGL_1.c.o
      _get_window_id in renderer_OpenGL_1.c.o
      ...
  "_SDL_SetPalette", referenced from:
      _gpu_copy_raw_surface_data in SDL_gpu.c.o
  "_SDL_SetVideoMode", referenced from:
      _Init in renderer_OpenGL_1_BASE.c.o
      _resize_window in renderer_OpenGL_1_BASE.c.o
      _Init in renderer_OpenGL_1.c.o
      _resize_window in renderer_OpenGL_1.c.o
      _Init in renderer_OpenGL_2.c.o
      _resize_window in renderer_OpenGL_2.c.o
      _Init in renderer_OpenGL_3.c.o
      ...
  "_SDL_WM_ToggleFullScreen", referenced from:
      _SetFullscreen in renderer_OpenGL_1_BASE.c.o
      _SetFullscreen in renderer_OpenGL_1.c.o
      _SetFullscreen in renderer_OpenGL_2.c.o
      _SetFullscreen in renderer_OpenGL_3.c.o
      _SetFullscreen in renderer_OpenGL_4.c.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[2]: *** [SDL_gpu/lib/SDL2_gpu.framework/Versions/A/SDL2_gpu] Error 1
make[1]: *** [src/CMakeFiles/SDL_gpu_shared.dir/all] Error 2
make: *** [all] Error 2
$ uname -mp
x86_64 i386
grimfang4 commented 2 years ago

I don't have a Catalina device handy, so all I can say from here is that these are linker errors from being unable to find functions provided by SDL. I would suggest you make sure that you can link something else with the SDL library you have installed. Some of the missing symbols are provided by both SDL and SDL2, but SDL_GetVideoSurface() and SDL_SetVideoMode() are only in SDL 1.2, which seems to conflict with the build target of SDL2_gpu.

ynfle commented 2 years ago

So I am able to compile and link the basic sdl2 program below

#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

using namespace std;

int main() {

    if(SDL_Init(SDL_INIT_VIDEO) < 0) {
        cout << "SDL init failed." << endl;
        return 1;
    }

    cout << "SDL Init succeeded." << endl;

    SDL_Quit();

    return 0;
}

with the following command g++ `sdl2-config --libs` `sdl2-config --cflags` test.cpp based on https://stackoverflow.com/questions/28016258/using-homebrew-installed-sdl2-with-xcode I'm not sure if this helps, makes a difference or anything.

Thanks in advance for your help