Why I cannot link the Mac framework file with CMake?

后端 未结 3 2026
我寻月下人不归
我寻月下人不归 2021-02-14 03:00

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         


        
相关标签:
3条回答
  • 2021-02-14 03:36

    Another solution is as follows:

    target_link_libraries(program "-framework CoreFoundation")
    target_link_libraries(program "-framework your_frame_work_name")
    set_target_properties(program PROPERTIES LINK_FLAGS "-Wl,-F/Library/Frameworks")
    
    0 讨论(0)
  • 2021-02-14 03:48

    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})
    
    0 讨论(0)
  • 2021-02-14 03:50

    You do not need all this hassle (at least with cmake 2.8.12).

    This works fine:

    target_link_libraries(program stdc++ "-framework Foundation" "-framework Cocoa" objc)
    

    When CMake sees a link parameter starting with "-", it does not prepend "-l" and passes the argument as-is to the linker (/usr/bin/c++).

    You need the quotes for frameworks so that CMake treats the two words as a single entry and does not add "-l" before "Foundation" for example.

    0 讨论(0)
提交回复
热议问题