Summary
This text will be hidden
I am trying to install and use sdl2 on an arm64 arch Mac.
I tried installing using homebrew with code brew install --build-from-source sdl2 sdl2_gfx
as seen on this thread .
After checking the architecture using lipo -info libSDL2.a
i’ve recieved arm64. However, once I tried to build a C code that uses SDL, i recieve the following error(s):
Undefined symbols for architecture arm64:
"_SDL_CreateRenderer", referenced from:
_main in main.c.o
"_SDL_CreateWindow", referenced from:
_main in main.c.o
"_SDL_GetError", referenced from:
_main in main.c.o
"_SDL_Init", referenced from:
_main in main.c.o
"_SDL_PollEvent", referenced from:
_log_events in main.c.o
"_SDL_Quit", referenced from:
_main in main.c.o
"_SDL_RenderFillRect", referenced from:
_main in main.c.o
"_SDL_RenderPresent", referenced from:
_main in main.c.o
"_SDL_SetRenderDrawColor", referenced from:
_main in main.c.o
ld: symbol(s) not found for architecture arm64
my CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.20)
project(SDL_test C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/opt/homebrew/include/SDL2 -D_THREAD_SAFE -L/opt/homebrew/lib ")
add_executable(SDL_test main.c)
changing the cmake_c_flags to set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lSDL2 -framework SDL")
creates an SDL.h not found error.
building the library myself didn’t work either.
Update: as it turns out, I’ve just misconfigured my CMakeLists.txt file.
using
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -v -g -Wall -I/opt/homebrew/include/SDL2 -D_THREAD_SAFE -L/opt/homebrew/lib -D_THREAD_SAFE") add_executable(SDL_test main.c) target_link_libraries(${PROJECT_NAME} SDL2) target_link_libraries(${PROJECT_NAME} SDL2_gfx)
does the trick.