不能链接MacOS框架与CMake [英] Can't link MacOS frameworks with CMake

查看:289
本文介绍了不能链接MacOS框架与CMake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用cmake()创建一个子项目,甚至是一个iphone的应用程序,结果是跨平台控制台可执行文件,其中包括一些继承自C ++的抽象

I'm trying to build a subproject with cmake (it's not an xcode project or even an app for iphone, the result is cross-platform console executable, which #includes some inherited from C++ abstract classes, written in objective-c++)

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

I'm using this guide to link mac os frameworks: 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中的重要部分

This is the important part in 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)
........


$ b b

这是我在尝试构建时:

And that's what i have when trying to build:

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.

它实际上找到了所有这些框架,但是不能链接,这会产生很多链接器错误。我很确定这是原因,因为我做了一个testproj使用XCode和它有相同的错误,直到我链接所有需要的框架。

It actually finds all these frameworks, but can't link, which produces a lot of linker errors. I'm pretty sure that that's the reason because i made a testproj using XCode and it has the same errors till i linked all the needed frameworks.

当我只是使用

FIND_LIBRARY(COREMEDIA_LIB CoreMedia)
...

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

then COREMEDIA_LIB is set to NOTFOUND - what's going on? :/

我搜索了很多,但没有什么:(感觉很迷失。

I googled a lot but nothing :( Feeling pretty much lost there.

推荐答案

很遗憾,没有人回答:(努力工作,得到的东西:你必须链接 frameworkname.framework TARGET_LINK_LIBRARIES 中的文件夹,但 fwname.framework / fwname 文件!

That's sad that noone answered :( Was working hard on this and got the thing: you have to link NOT the frameworkname.framework folder in the TARGET_LINK_LIBRARIES, but the fwname.framework/fwname file!!! Now it works that way.

已变更的巨集为:

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)

希望它对某人有用...

Hope it will be useful for someone...

这篇关于不能链接MacOS框架与CMake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆