4

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}
)
Community
  • 1
  • 1
vgonisanz
  • 11,831
  • 13
  • 78
  • 130

3 Answers3

3

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.

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
2

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.

Gui13
  • 12,993
  • 17
  • 57
  • 104
  • I have trying changing order, trying several combinations, but it didn´t work. I think the correct order is OGRE, OPENCV, and then my libraries, like the CmakeLists.txt posted. – vgonisanz Nov 28 '13 at 09:46
0

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

Geraud.ch
  • 1,499
  • 10
  • 15
  • Yes, I have added them. The problem is that the project is not finding SOME of the functions. The functions are in the library because I can see them using otool, and using other functions are found in ARMV7s, but some of them no. – vgonisanz Nov 28 '13 at 09:34