Results 1 to 4 of 4
  1. #1


    Member Since
    Oct 10, 2008
    Posts
    2
    XCode static library linking ld error
    Hi,

    I am trying to link a static library written by me and compiled with gcc (libtest.a) with XCode 3.1 project. After writing the library, I dragged the library file to the Frameworks folder as I've been doing previously.

    But now whenever I call a function from the library( int myFuction( int ) ) and build the project I get the following ld error:

    ld warning: in /Users/dev/lib/libtest.a, file is not of required architecture

    Undefined symbols:
    "_myFunction", referenced from:
    _test_Function in mytest.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status


    It seems that lib file is being located properly but for some reason ld can't find symbols in the file. Anyone have any idea how I go about fixing this problem? Help will be appreciated.


    --
    Thanks,
    Salman

  2. #2

    xstep's Avatar
    Member Since
    Jun 25, 2005
    Location
    On the road
    Posts
    3,231
    Specs:
    2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
    Quote Originally Posted by MSalman View Post
    file is not of required architecture
    If I was to guess, I'd say that part sounds like you have compiled it for the opposite architecture from what you are compiling the the calling code for.
    CameraTime - Time lapse photography for novice and advanced users.

    When asking questions, post the version of your software. You'll receive better answers.

    Please post your results to the thread as it is good feedback.

  3. #3


    Member Since
    Oct 10, 2008
    Posts
    2
    Quote Originally Posted by xstep View Post
    If I was to guess, I'd say that part sounds like you have compiled it for the opposite architecture from what you are compiling the the calling code for.
    I figured that out

    Well, actually I forgot to mention that I compiled this file with the arm-apple-darwin-gcc compiler (cross compiling) and the XCode project is for iPhone as well.

    Isn't compiling the file using the arm-apple-darwin-gcc and XCode one and the same thing. Don't they have the same architecture?

  4. #4


    Member Since
    Nov 05, 2008
    Posts
    1
    you need to add -dynamiclib flag
    To fix the error, add the "-dynamiclib" flag.
    Something like: gcc -dynamiclib *.c -o libmylibname.dylib
    You can find more at:
    <http://developer.apple.com/documentation/DeveloperTools/Conceptual/DynamicLibraries/Articles/CreatingDynamicLibraries.html#//apple_ref/doc/uid/TP40002073>

    or for me it works like this.

    g++ -dynamiclib -undefined dynamic_lookup -single_module -o libBlah.dylib *.o

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. To create single static(.a)library from several static(.a)files in iphone
    By anair in forum iPhone Hardware and Accessories
    Replies: 0
    Last Post: 10-09-2013, 03:53 AM
  2. Replies: 0
    Last Post: 10-09-2013, 03:53 AM
  3. Xcode linking files
    By Antonious in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 01-15-2011, 02:38 AM
  4. Linking Allegro to Xcode
    By rhoff37 in forum OS X - Apps and Games
    Replies: 3
    Last Post: 01-03-2011, 10:14 PM
  5. XCode linking question
    By robin in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 07-02-2004, 06:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •