Linker error (only simulator) with own library after update to iPhone SDK 4.0

Discussion in 'iOS Programming' started by fas, Jun 30, 2010.

  1. fas macrumors newbie

    Jun 30, 2010
    Hey all,

    I already asked this in another forum with no result yet, so sorry for cross-posting if you already read this.

    I recently updated to iPhone SDK 4.0 and are no longer able to build my project for the iPhone simulator. The problem is that classes of one of my own libraries can no longer be found by ld:
    "_OBJC_CLASS_$_Book", referenced from:
       objc-class-ref-to-Book in Category.o
       (maybe you meant: ...)
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    I already read some other posts about similar problems, like e.g. here. "Unfortunately", my problem has nothing to do with a SDK framework, but with my own lib, so the solutions mentioned there are not applicable here.

    The library is included under "Link Binary With Libraries" of my target, library search paths are correct (checked this with XCode and with a plain text editor directly in my project file) and correctly added to the gcc command.

    I'm using iPhone Simulator 3.2 as Base SDK, but the same problem occurs with SDK 4.0. Again, this works with my device target but not with my simulator target. It worked with both, though, before I updated from iPhone SDK 3.2 to 4.0. I was also able to reproduce this error by creating a new project with only one file and the linked lib. However, the lib should be okay as it worked with simulator 3.2 before I updated XCode and my SDK.

    More Facts: Mac OS X 10.6.3, XCode 3.2.3 64-Bit, iPhone OS 3.2, GCC 4.2

    Any help would be highly appreciated.


    After reinstalling SDK 3.2, everything worked as expected again. It must be noted, that the SDKs in folder /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs are overwritten with each installation. I then tried to reinstall SDK 4.0 again and the same error as above occurred. I didn't change anything in my project and always used 3.2 as Base SDK.

    The problem can therefore possibly be narrowed down to the following options:
    • Apple changed sth. in the Simulator SDK 3.2 that causes the problem
    • a change in XCode 3.2.3 causes the problem
    • wrong/missing compiler flags while building my own library (those flags, however, would only cause problems with a changed SDK or the changed IDE)

    I also did a folder diff on /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk for both the old and the new version of this folder. It turned out that there are actually minor changes within the "same" SDK. I still think it's an IDE/compiler flag problem, though.

    Anybody any ideas?
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Make sure that you recompile the library with the 3.2.3 toolset. Something did change.
  3. fas thread starter macrumors newbie

    Jun 30, 2010
    Thanks for your reply. I'm compiling with iPhoneSimulator3.2.sdk. Could you explain what you mean by recompiling with the 3.2.3 toolset?
    Maybe my call to compile the library helps a bit, is there anything else I need? Or a wrong flag?

    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -Wall -g -std=gnu99 -I. -I../../ -I../../libevent_ios_i386/include -D_REENTRANT -DSDK_IPHONESIMULATOR -DMSG_BACKEND_SIMPLE -DSTORAGE_BACKEND_SIMPLE -D__IPHONE_OS_VERSION_MIN_REQUIRED=30200 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk -mmacosx-version-min=10.6 -O -c msgbuf.c.o -o libcore_ios_i386_iphonesimulator3.2.a
  4. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    You need to throw away the old copy of your lib and build a new one with the same version of Xcode that you're using to build the application.

    Apparently the 3.2.3 Sim uses the modern runtime, which is what the device uses but not what the Sim in the 3.2.2 and earlier versions of Xcode used.

    Are you building the lib from the command line or from a project?
  5. fas thread starter macrumors newbie

    Jun 30, 2010
    I'm building the lib from command line and add it to an XCode project. This project is then build via XCode, which only works for device, not for simulator. That means, XCode is not involved in the build process of the lib.
  6. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    OK, I would build the static lib using an Xcode project and add the Xcode project to the main app project. But that's what I'd do.

    If you're building from the command line you just need to make sure the command line is the same as what Xcode would use and that you're using the same SDK and tools that Xcode is using.

    You might want to build a small test project that builds a .a file with similar settings to the ones your app project uses and compare the command line.
  7. fas thread starter macrumors newbie

    Jun 30, 2010
    Thanks a lot for this suggestion. I compared both compiler calls and was finally able to figure out which flags were missing in my Makefile to build the lib. So, if anybody else has problems linking his/her own static lib to a target in XCode 3.2.3 (using iPhoneSimulator3.2.sdk or iPhoneSimulator4.0.sdk), you need to build your lib with the following two flags:


Share This Page