vgonisanz
vgonisanz

Reputation: 11930

iOS static library does not link XCODE 5 iOS 7

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.


So, if the library work in another project, and the functions are inside, why the linking problem?



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}
)

Upvotes: 4

Views: 3055

Answers (3)

Jav_Rock
Jav_Rock

Reputation: 22245

You must add one time the flag -ObjC and -force_load for every lib that you want add all functions to link, avoiding fail caused by non added functions.

For example, you must change your cpp flags adding to lib boost_system because that is causing linker problem:

SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lmesaglsl2 -force_load -lboost_system -lboost_chrono -lboost_date_time -lboost_thread -lFreeType -lFreeImage -lzzip -lz -lc++ -lforce_load -lfoo")

and apply this flag for every lib you need.

Upvotes: 3

Gui13
Gui13

Reputation: 13551

Clang's linker is a bit strict on library linking order, could you try swapping the linking order in your project to see if this is the reason?

Could you produce here the linking step command line? You just have to click on the button there: enter image description here

Also, maybe try to remove the -lfoo from your Other Linker options, since adding the .a to your project is sufficient.

Upvotes: 2

Geraud.ch
Geraud.ch

Reputation: 1499

Basic question, have you added the foo.a to the linked library? For the good target (open right panel and check that the lib is linked with all targets needed)?

Upvotes: 0

Related Questions