2

我正在尝试将 Mac OS X 框架使用添加到我的程序中,其中包括一些带有 Objective-c++ 代码的文件。

它确实适用于SET (CMAKE_EXE_LINKER_FLAGS "-framework CoreMedia -framework ... "),但我不太喜欢这种方式,而且似乎是错误的。

这是实际添加的 CMake 部分,但它不起作用,我真的不知道我错过了什么 :( 我尝试使用

link_directories("${CMAKE_OSX_SYSROOT}/System/Library/Frameworks")
include_directories("${CMAKE_OSX_SYSROOT}/System/Library/Frameworks")

但这根本没有帮助。所以这里是代码:

add_executable(myprogram src/myprogram.cpp)

FIND_LIBRARY(COREMEDIA_LIB NAMES CoreMedia)
FIND_LIBRARY(COREVIDEO_LIB NAMES CoreVideo)
FIND_LIBRARY(FOUNDATION_LIB NAMES Foundation)
FIND_LIBRARY(AVFOUNDATION_LIB NAMES AVFoundation)

target_link_libraries(myprogram ${COREMEDIA_LIB})
target_link_libraries(myprogram ${COREVIDEO_LIB})
target_link_libraries(myprogram ${FOUNDATION_LIB})
target_link_libraries(myprogram ${AVFOUNDATION_LIB})

它会产生 cmake 错误:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
AVFOUNDATION_LIB
linked by target "myprogram" in directory <some directory containing app>

<... other 3 are here aswell ...>
4

2 回答 2

2

这对我有用:

IF (APPLE)
   find_library(COREMIDI_LIBRARY CoreMIDI)
   find_library(COREFOUNDATION_LIBRARY CoreFoundation)
   target_link_libraries(myprogram ${COREFOUNDATION_LIBRARY} ${COREMIDI_LIBRARY})
ENDIF (APPLE)
于 2014-04-21T17:21:29.473 回答
2

好的,我知道了。我需要将 PATHS 变量指定为${CMAKE_OSX_SYSROOT}/System/Library. 我不知道为什么,但它无法自动在这个文件夹中找到它,虽然认为它是一个标准文件夹......

所以这样调用:

例如,当我链接AVFoundation框架时:

add_executable(myprogram)

find_library(SOME_VAR
    NAMES AVFoundation
    PATHS ${CMAKE_OSX_SYSROOT}/System/Library
    PATH_SUFFIXES Frameworks
    NO_DEFAULT_PATH)

接着

target_link_libraries(myprogram "${SOME_VAR}/AVFoundation")

希望它会帮助某人。

于 2012-09-24T16:54:14.227 回答