Error in xcode project: ld: library not found for -lcrt1.10.6.o

后端 未结 12 1062
日久生厌
日久生厌 2020-12-05 07:09

Just upgraded to Snow Leopard, installed Xcode 3.2, then installed iPhone SDK 3 for SL.

In a project, I now get the following error on build:

相关标签:
12条回答
  • 2020-12-05 07:52

    The compiler normally uses crt1.o combined with crt[i/n].o and crt[begin/end].o to support the constructors and destructors (functions called before and after main and exit).

    This error could be caused by this missing library file for the specific deployment target.

    First, do some investigation, like:

    1. List all your deployment targets:

      ls -la /Developer/SDKs
      
    2. Find which crt1 libraries do you have for which environment

      find /Developer/SDKs -name crt1\*
      

      You could see something like:

      /Developer/SDKs/MacOSX10.5.sdk/usr/lib/crt1.10.5.o
      /Developer/SDKs/MacOSX10.5.sdk/usr/lib/crt1.o
      /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.5.o
      /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.6.o
      /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.o
      

    As you can see in above example, crt1.10.6.o is missing for MacOSX10.5.

    Solution 1

    You can solve that by creating the link to the missing file pointed to the other environment, or you could change your deployment target. E.g.

    ln -s /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.6.o /Developer/SDKs/MacOSX10.5.sdk/usr/lib/
    

    Other reason why it's missing, is that you could have different gcc installed in your system. E.g.:

    which gcc
    xcrun -find gcc
    brew list | grep gcc; brew list gcc47
    

    Solution 2

    So when you're compiling using make, you can actually specify the right compiler by CC variable. E.g.

    CC=/path/to/gcc-3.4 make
    

    Solution 3

    What you can also try is specifying the right target deployment environment variable for gcc, e.g.:

    export MACOSX_DEPLOYMENT_TARGET=10.5
    

    If this works, then you can add this library path to your shell profile (~/.profile). E.g.

    export C_INCLUDE_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/include
    
    export LIBRARY_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/lib
    

    Or by temporary exporting them.


    How to test

    Create the example conftest.c file with the following code:

    #ifdef __GNUC__
      yes;
    #endif
    

    And try to compile it via:

    gcc conftest.c
    cc conftest.c
    cc conftest.cc conftest.c
    
    0 讨论(0)
  • 2020-12-05 07:53

    I was able to fix this problem by adding the following to my Makefile:

    CFLAGS="$(OTHER_CFLAGS) -mmacosx-version-min=10.5"
    LDFLAGS="$(OTHER_LDFLAGS) -mmacosx-version-min=10.5"
    

    Ostensibly, this is only required when building outside of Xcode. This problem frustrated me long enough that I figured it would be useful to share my experience here.

    0 讨论(0)
  • 2020-12-05 07:54

    It looks like you're picking up libraries from /usr/lib, which is wholly inappropriate for the iPhone SDK. I would assume you've changed your build settings to add /usr/lib to the library search paths. This should be completely unnecessary in the first place, as /usr/lib is in the compiler's standard search paths, but if you need to have a modified search path like this, make sure to use $(SDKROOT)/usr/lib instead.

    0 讨论(0)
  • 2020-12-05 08:00

    This problem solved by setting Mac OS X Deployment Target to 10.5 and after this set back to Compiler Default :)

    0 讨论(0)
  • 2020-12-05 08:02

    I had the same error message, none of the above solutions worked for me. I resolved it by deleting the *.pbxuser and *.mode1v3 files inside the xcodeproj file.

    1. Control/click the xcode *.xcodeproj file
    2. Select the "show package contents" option from the menu
    3. A window will open with the contents
    4. Delete the pbxuser/mode1v3 files that start with your user name
    5. Rebuild the project
    0 讨论(0)
  • 2020-12-05 08:03

    Setting deployment target to compiler defaults solved the problem. Don't change anything else.

    0 讨论(0)
提交回复
热议问题