CLion project CMakeLists.txt cannot find IOKit framework

1 week ago 4
ARTICLE AD BOX

I have a CMake project in CLion with the following structure

│ ├────dependencies │ │ │ ├─include │ │ ─────GLFW/glfw.h │ │ │ └─lib-arm64 │ ─────libglfw3.a ├────main.cpp │ └────CMakeLists.txt

This is my CMakeLists.txt

project(OpenGLProject1) set(CMAKE_CXX_STANDARD 20) add_executable(OpenGLProject1 main.cpp) find_library( DEP_LIBRARY_PATH NAME glfw3 PATHS "${CMAKE_SOURCE_DIR}/dependencies/lib-arm64" NO_DEFAULT_PATH ) if(NOT DEP_LIBRARY_PATH) message(FATAL_ERROR "Could not find 'libglfw3.a' in ${CMAKE_SOURCE_DIR}/dependencies/lib-arm64") endif() target_include_directories( OpenGLProject1 PUBLIC "${CMAKE_SOURCE_DIR}/dependencies/include" ) target_link_libraries( OpenGLProject1 PUBLIC ${DEP_LIBRARY_PATH} ) target_link_libraries( OpenGLProject1 PRIVATE -framework Cocoa -framework IOKit -framework CoreFoundation ) message(STATUS "SUCCESS!")

But the linker is complaining about not being able to find IOKit framework. From what I can tell, CMake should be able to search and find the .framework from /System/Library/Frameworks which I have verified, exisits.

Here is the complete error

FAILED: OpenGLProject1 : && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/OpenGLProject1.dir/main.cpp.o -o OpenGLProject1 /Users/sushant/CLionProjects/OpenGLProject1/dependencies/lib-arm64/libglfw3.a -framework -lCocoa -lIOKit -lCoreFoundation && : ld: library 'IOKit' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.

Any pointers no how I can resolve this issue?

Read Entire Article