8

我正在尝试使用cmake构建一个子项目(它不是xcode项目,甚至不是iphone的应用程序,结果是跨平台控制台可执行文件,其中#includes一些从C++抽象类继承的,用objective-c++编写的)

我正在使用本指南链接 mac os 框架:http ://www.vtk.org/Wiki/CMake:HowToUseExistingOSXFrameworks

这个宏:

macro(ADD_FRAMEWORK fwname appname)
find_library(FRAMEWORK_${fwname}
    NAMES ${fwname}
    PATHS ${CMAKE_OSX_SYSROOT}/System/Library
    PATH_SUFFIXES Frameworks
    NO_DEFAULT_PATH)
if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND)
    MESSAGE(ERROR ": Framework ${fwname} not found")
else()
    TARGET_LINK_LIBRARIES(${appname} ${FRAMEWORK_${fwname}})
    MESSAGE(STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}")
endif()
endmacro(ADD_FRAMEWORK)

这是 CMakeLists.txt 中的重要部分

project(myprojectname)
........
add_executable(mytarget src/mytarget.cpp)

add_framework(CoreMedia mytarget)
add_framework(CoreVideo mytarget)
add_framework(AVFoundation mytarget)
add_framework(Foundation mytarget)
........

这就是我在尝试构建时所拥有的:

WARNING: Target "mytarget" requests linking to directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/CoreMedia.framework".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "mytarget" requests linking to directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/CoreVideo.framework".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "mytarget" requests linking to directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/AVFoundation.framework".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "mytarget" requests linking to directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/Foundation.framework".  Targets may link only to libraries.  CMake is dropping the item.

它实际上找到了所有这些框架,但无法链接,这会产生很多链接器错误。我很确定这就是原因,因为我使用 XCode 制作了一个 testproj,并且在我链接所有需要的框架之前它具有相同的错误。

当我只是使用

FIND_LIBRARY(COREMEDIA_LIB CoreMedia)
...

然后COREMEDIA_LIB设置为NOTFOUND- 发生了什么事?:/

我用谷歌搜索了很多,但什么也没有:(在那里感觉很迷茫。

4

1 回答 1

23

明白了:你必须链接的不是frameworkname.framework文件夹TARGET_LINK_LIBRARIES,而是fwname.framework/fwname文件!现在它就是这样工作的。

修改后的宏是这样的:

macro(ADD_FRAMEWORK fwname appname)
    find_library(FRAMEWORK_${fwname}
    NAMES ${fwname}
    PATHS ${CMAKE_OSX_SYSROOT}/System/Library
    PATH_SUFFIXES Frameworks
    NO_DEFAULT_PATH)
    if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND)
        MESSAGE(ERROR ": Framework ${fwname} not found")
    else()
        TARGET_LINK_LIBRARIES(${appname} "${FRAMEWORK_${fwname}}/${fwname}")
        MESSAGE(STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}")
    endif()
endmacro(ADD_FRAMEWORK)

希望它对某人有用...

于 2012-09-24T16:47:21.173 回答