gpt4 book ai didi

iphone - CMake 和 XCode : "cannot find interface declaration for ' NSObject'"

转载 作者:行者123 更新时间:2023-12-03 20:34:06 24 4
gpt4 key购买 nike

我正在尝试使用 CMake 生成 XCode 项目,但遇到了一些问题。

CMake 生成的项目很好,但后来很明显它没有链接到 Foundation 和 UIKit 框架。我对 CMake 还很陌生,一直在努力克服这个问题,但没有成功。

CMake 输出(部分):

...
Framework Foundation found at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/Frameworks/Foundation.framework
Framework CoreGraphics found at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/Frameworks/CoreGraphics.framework
Framework UIKit found at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/Frameworks/UIKit.framework
Configuring done
Generating done

下面是我的 CMakeLists.txt 文件(由 SO 上的几个答案组合而成):

cmake_minimum_required(VERSION 2.8)

macro(ADD_FRAMEWORK fwname appname libpath)
find_library(FRAMEWORK_${fwname}
NAMES ${fwname}
PATHS ${libpath}

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)

project(test)
set(NAME test)
set (libpath /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library)


file(GLOB headers *.h)
file(GLOB sources *.m)

set(CMAKE_OSX_SYSROOT iphoneos4.2)
set(CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD_32_BIT))
set(CMAKE_CXX_FLAGS "-x objective-c++")
set(CMAKE_EXE_LINKER_FLAGS
"-framework AudioToolbox -framework CoreGraphics -framework QuartzCore -framework UIKit -framework Foundation"
)

set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.mycompany.\${PRODUCT_NAME:identifier}")
set(APP_TYPE MACOSX_BUNDLE)

add_executable(${NAME}
${APP_TYPE}
${headers}
${sources}
)

ADD_FRAMEWORK(Foundation ${NAME} ${libpath})
ADD_FRAMEWORK(CoreGraphics ${NAME} ${libpath})
ADD_FRAMEWORK(UIKit ${NAME} ${libpath})

# code signing
set_target_properties(${NAME} PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer: Some Name")

最佳答案

我有一些建议:

  • 不要使用add_framework。这使得 CMake 设置项目属性 FRAMEWORK_SEARCH_PATHS ,这不知何故搞砸了一切。而是使用命令行开关 -framework
  • 对于 CMAKE_OSX_SYSROOT,您可以只使用 iphoneos
  • 您不需要CMAKE_CXX_FLAGS

有了这些你可能会更幸运。到目前为止,我设法克服了大部分链接错误。

关于iphone - CMake 和 XCode : "cannot find interface declaration for ' NSObject'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5473448/

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