我在 OSX 10.9 上使用 XCode 5.0.1,并且正在链接 libc++(LLVM C++ 标准库)和有效架构 armv7;armv7s 和两者。
1º 我创建了一个使用 OpenCV2.framework + foo 使用 Cmake 的项目,使用 foo.a 创建一个 XCode 项目。我的可执行链接 OpenCV2.framework + foo.a 可以完美运行,编译和链接。
2º 我使用 Ogre 的模板创建了另一个项目。该项目完美运行。
3º 然后,我尝试将 foo.a 添加到新项目中,以制作与我的可执行文件在步骤 1 中使用的相同的东西。
- 添加头搜索路径的包含路径。
- 将库路径添加到库搜索路径。
- 将-ObjC -all_load -lfoo 作为This和this添加到其他链接器路径
- 添加项目所需的代码源。
- 当我使用对 foo 函数的调用时 --> 链接问题:架构 armv7 到 foo::functionname() 的未定义符号。
- 信息:
- 该调用与第一个项目完全一样,即工作。
- 使用 otool -hv foo.a --> 我看到所有 lib.o 的 cputype 都是 ARV V7
- 使用 lipo -info foo.a --> 当我使用该拱门时,我看到 foo.a 是 armv7 或 armv7s。
- 使用 nm foo.a | grep functionname --> 我看到这个函数在 armv7 和 armv7s 的库中,当编译两个arch时。
那么,如果库在另一个项目中工作,并且函数在里面,为什么会出现链接问题?
- 信息 2:
- 将 foo 目标添加到 ogre 的项目中,同样的问题。按照这个方法。
- 添加目标依赖项也不起作用。
我编译这个示例的 CmakeList 是:
# /////////////////////////////////////////////////////////
# //SAMPLE
# /////////////////////////////////////////////////////////
# 3rdParty (OGRE LOCATION)
set(OGRE_SDK_ROOT /Users/vgoni/Librerias/ogre1.9-pre/OgreSDK/ CACHE PATH "Ogre SDK ROOT")
set(OGRE_DEPENDENCIES_DIR ${OGRE_SDK_ROOT}/iOSDependencies CACHE PATH "Ogre SDK DEP")
# Set up project
SET(PROJ_NAME ogreIOS)
PROJECT( ${PROJ_NAME} )
SET(PRODUCT_NAME ${PROJ_NAME})
SET(EXECUTABLE_NAME ${PROJ_NAME}Executable)
# Add variable to generate iphone project in ADD_EXECUTABLE
SET(APP_TYPE MACOSX_BUNDLE)
# Headers
SET(${PROJ_NAME}_HEADERS
include/OgreStaticPluginLoader.h
include/OgreDemoApp.h
include/OgreFramework.h
include/AppDelegate.h
)
# Source
SET(${PROJ_NAME}_SRC
src/OgreFramework.cpp
src/OgreDemoApp.cpp
src/main.mm
)
# Add there files to Resources package into XCODE
SET_SOURCE_FILES_PROPERTIES(
resources/ogre.cfg
resources/plugins.cfg
resources/resources.cfg
resources/ogreiosSample-Info.plist
resources/ogreiosSample-Prefix.pch
resources/en.lproj/InfoPlist.strings
PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
)
# Include self directories
INCLUDE_DIRECTORIES( include )
# Include OGRE headers needed
INCLUDE_DIRECTORIES( ${OGRE_SDK_ROOT}/include )
INCLUDE_DIRECTORIES( ${OGRE_SDK_ROOT}/include/OIS )
INCLUDE_DIRECTORIES( ${OGRE_SDK_ROOT}/include/OGRE )
INCLUDE_DIRECTORIES( ${OGRE_SDK_ROOT}/include/OGRE/Overlay )
INCLUDE_DIRECTORIES( ${OGRE_SDK_ROOT}/include/OGRE/iOS )
INCLUDE_DIRECTORIES( ${OGRE_SDK_ROOT}/include/OGRE/RTShaderSystem )
INCLUDE_DIRECTORIES( ${OGRE_SDK_ROOT}/include/OGRE/RenderSystems/GLES2 )
INCLUDE_DIRECTORIES( ${OGRE_SDK_ROOT}/iOSDependencies/include )
# Link Directories where libraries needed are
LINK_DIRECTORIES( ${OGRE_SDK_ROOT}/lib/Release )
LINK_DIRECTORIES( ${OGRE_SDK_ROOT}/iOSDependencies/lib )
LINK_DIRECTORIES( ${OGRE_SDK_ROOT}/iOSDependencies/lib/Release )
# Add ogre & boots libraries flags
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lmesaglsl2 -lboost_system -lboost_chrono -lboost_date_time -lboost_thread -lFreeType -lFreeImage -lzzip -lz -lc++ -lforce_load -lfoo")
# foo is my library, force to load all to avoid fail in linking
# 3rdParty ogre libraries
SET(OGRE_LIBS OIS OgreMainStatic RenderSystem_GLES2Static OgreRTShaderSystemStatic )
# Link the libraries needed
#TARGET_LINK_LIBRARIES (${PROJ_NAME} ${OGRE_LIBS})
# Create executable for iOS
ADD_EXECUTABLE(
${EXECUTABLE_NAME}
${APP_TYPE}
${${PROJ_NAME}_HEADERS}
${${PROJ_NAME}_SRC}
)
# Adding info to XCode project
#set_target_properties(${EXECUTABLE_NAME} PROPERTIES
#MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/resources/Info.plist)
# Change name to make work Macros
SET(PROJ_NAME ogreIOSExecutable)
# Macro to add frameworks to Sample Executable
link_ios_framework(AssetsLibrary ${EXECUTABLE_NAME})
link_ios_framework(AVFoundation ${EXECUTABLE_NAME})
link_ios_framework(CoreMedia ${EXECUTABLE_NAME})
link_ios_framework(CoreGraphics ${EXECUTABLE_NAME})
link_ios_framework(CoreVideo ${EXECUTABLE_NAME})
link_ios_framework(ImageIO ${EXECUTABLE_NAME})
link_ios_framework(Foundation ${EXECUTABLE_NAME})
link_ios_framework(OpenGLES ${EXECUTABLE_NAME})
link_ios_framework(QuartzCore ${EXECUTABLE_NAME})
link_ios_framework(UIKit ${EXECUTABLE_NAME})
# Needed dependencies
link_ios_sdk(libc++.1.dylib ${EXECUTABLE_NAME})
link_ios_sdk(libz.dylib ${EXECUTABLE_NAME})
#Add OpenCV Libraries to link
TARGET_LINK_LIBRARIES (${PROJ_NAME} ${OpenCV_LIBS})
LINK_DIRECTORIES(
${LIBRARY_OUTPUT_PATH}
)