I have written sdl2 game in pure c on m1 mac using vscode+homebrew pkg manager with makefile and it works successfully. I used hombrew to install the pkgs of sdl2(like sdl2_image,sdl2_gfx) and included them in my makefile, and every thing just works great. However, when i decided to use clion with cmake to write sdl2 games, there's something wrong with my cmake. I have discoverd a very good code example from youtube, which is:https://github.com/tsoding/profun/tree/master/procedural(Thanks a lot for the guy's great work!).I download his whole project and used his cmake, it works great on my ** linux machine however falied on my m1 mac**. The cmake file looks like:
cmake_minimum_required(VERSION 3.7)
project(procedural C)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
find_package(PkgConfig)
pkg_check_modules(SDL2_GFX SDL2_gfx)
include_directories(${SDL2_GFX_INCLUDE_DIRS})
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -Wall -Werror")
set(SRCS
main.c
logic.c
rendering.c
)
set(HEADERS
logic.h
rendering.h
game.h
)
add_executable(procedural ${SRCS} ${HEADERS})
target_link_libraries(procedural ${SDL2_LIBRARIES} ${SDL2_GFX_LIBRARIES})
This cmake helped my clion to find the header files and code completion, and when i hit
cmake .
everything works great, it complies and the console shows
The C compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found PkgConfig: /opt/homebrew/bin/pkg-config (found version "0.29.2")
-- Checking for module 'SDL2_gfx'
-- Found SDL2_gfx, version 1.0.2
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mac/Downloads/prof/procedural
however, when i hit
make
the code cannot run and the console shows:
[ 25%] Building C object CMakeFiles/procedural.dir/main.c.o
[ 50%] Building C object CMakeFiles/procedural.dir/logic.c.o
[ 75%] Building C object CMakeFiles/procedural.dir/rendering.c.o
[100%] Linking C executable procedural
ld: library not found for -lSDL2_gfx
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [procedural] Error 1
make[1]: *** [CMakeFiles/procedural.dir/all] Error 2
make: *** [all] Error 2
it says that it cannot find sdl2_gfx, which is very confusing. can anyone help me to figure it out? I will be more than appreciated! I really want to use cmake instead of make(I want the cross platform feature), and I really want to use cmake with homebrew.