gpt4 book ai didi

ios - 无法将 MacOS 框架与 CMake 链接

转载 作者:可可西里 更新时间:2023-11-01 03:37:18 28 4
gpt4 key购买 nike

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

我正在使用本指南链接 mac 操作系统框架: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 - 这是怎么回事? :/

我在谷歌上搜索了很多但一无所获 :( 感觉很迷茫。

最佳答案

明白了:您必须不是TARGET_LINK_LIBRARIES 中的frameworkname.framework 文件夹,但是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)

希望对某人有用...

关于ios - 无法将 MacOS 框架与 CMake 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12547624/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com