Issue
I have a question related to CMake in MAC. I make sure that the executable program will link the framework and libraries correctly with the following codes:
link_directories(directory_to_framework_and_libs)
add_executable(program ${FILE_LIST})
target_link_libraries(program framework_name lib1 lib2)
In the first line code, I denote the location where the executable program can search for the framework and libraries. In the third line code, the framework and the libraries will link to the executable program. However, when I compile the xcode.project created from the cmake file with Xcode 4, the project keeps complaining that it cannot find -lframework_name
: ld: library not found -lframework_name
Any ideas will be appreciated.
Solution
You can't link to a framework this way, you have to use find_library
as it includes some special handling for frameworks on OSX.
Also, don't use link_directories
, CMake use full paths to libraries and it's not needed.
Here's some simple example with AudioUnit:
find_library(AUDIO_UNIT AudioUnit)
if (NOT AUDIO_UNIT)
message(FATAL_ERROR "AudioUnit not found")
endif()
add_executable(program ${program_SOURCES})
target_link_libraries(program ${AUDIO_UNIT})
Answered By - Guillaume Answer Checked By - Marilyn (WPSolving Volunteer)