开发者

CMake and XCode: "cannot find interface declaration for 'NSObject'"

开发者 https://www.devze.com 2023-02-20 17:50 出处:网络
I am trying to generate an XCode project with CMake, but I ran into some problems. CMake generates the project fine, but afterwards it becomes apparent that it hasn\'t linked to the Foundation and UI

I am trying to generate an XCode project with CMake, but I ran into some problems.

CMake generates the project fine, but afterwards it becomes apparent that it hasn't linked to the Foundation and UIKit frameworks. I am pretty new to CMake and have been trying to overcome this, but with no success.

The CMake output (partial):

...
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

Below is my CMakeLists.txt file (put together from several answers on 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_pro开发者_运维技巧perties(${NAME} PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer: Some Name")


I have a few suggestions:

  • don't use add_framework. This makes CMake set the project property FRAMEWORK_SEARCH_PATHS which somehow screws up everything. Instead use the command line switch -framework
  • for CMAKE_OSX_SYSROOT you can just use iphoneos
  • you don't need the CMAKE_CXX_FLAGS

With these you might have more luck. I managed to get past most of the link errors so far.


Try the following rule in your CMakeLists.txt:

link_directories(\${HOME}/\${SDKROOT}/lib)
0

精彩评论

暂无评论...
验证码 换一张
取 消