I´m using XCode 5.0.1 on OSX 10.9 and I ´m linking libc++ (LLVM C++ standart library) and Valid architectures armv7; armv7s and both.
1º I have created a project that use OpenCV2.framework + foo using Cmake, create a XCode project using foo.a . My executable link OpenCV2.framework + foo.a and work perfectly, compile and link.
2º I have used Ogre´s template to create another project. This project work perfectly.
3º Then, I try to add foo.a to the new project, to make the same things that my executable used in step 1.
- Adding includes path to Header Search Paths.
- Adding library path to Library Search Paths.
- Adding -ObjC -all_load -lfoo to Other Linker Paths as This and this
- Adding code source needed in the project.
- When I´m using calls to foo functions --> Linking problem: Undefined symbols for architecture armv7 to foo::functionname().
- INFO:
- That call is exactly like the first project, that work.
- Using otool -hv foo.a --> I see the cputype is ARV V7 to all lib.o
- Using lipo -info foo.a --> I see foo.a is armv7 or armv7s when i use that arch.
- Using nm foo.a | grep functionname --> I see the function is inside the library in armv7 and armv7s when compile both arch.
So, if the library work in another project, and the functions are inside, why the linking problem?
- INFO 2:
- Adding the foo target to the ogre´s project, same problem. Following THIS method.
- Adding target dependencies doesnt work neither.
My CmakeList to compile this sample is:
# /////////////////////////////////////////////////////////
# //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}
)