19

I've been scouring SO and Google but haven't found anything helpful yet.

We're updating our existing iOS project to build against iOS 5.

Our project has two targets, the first is our static library and the second is a Unit Test application (GHUnit).

When building the unit test target it successfully compiles the static library, but then fails to link against it with the following output:

Ld /Users/XXXXXX/Library/Developer/Xcode/DerivedData/XXXXXXLibrary-egoqfplddstqvwaigwuiqfqplcax/Build/Products/Debug-iphonesimulator/UnitTests.app/UnitTests normal i386
    cd /Users/XXXXXX/Documents/iOS/trunk
    setenv MACOSX_DEPLOYMENT_TARGET 10.6
    setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -L/Users/XXXXXX/Library/Developer/Xcode/DerivedData/XXXXXXLibrary-egoqfplddstqvwaigwuiqfqplcax/Build/Products/Debug-iphonesimulator -F/Users/XXXXXX/Library/Developer/Xcode/DerivedData/XXXXXXLibrary-egoqfplddstqvwaigwuiqfqplcax/Build/Products/Debug-iphonesimulator -F/Users/XXXXXX/Documents/iOS/trunk -F/Users/XXXXXX/Documents/iOS/trunk/UnitTests -filelist /Users/XXXXXX/Library/Developer/Xcode/DerivedData/XXXXXXLibrary-egoqfplddstqvwaigwuiqfqplcax/Build/Intermediates/XXXXXXLibrary.build/Debug-iphonesimulator/UnitTests.build/Objects-normal/i386/UnitTests.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -ObjC -all_load -Wl -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50000 -framework SystemConfiguration -framework CoreLocation -framework CoreData /Users/XXXXXX/Library/Developer/Xcode/DerivedData/XXXXXXLibrary-egoqfplddstqvwaigwuiqfqplcax/Build/Products/Debug-iphonesimulator/XXXXXX.a -framework GHUnitIOS -framework CoreGraphics -framework Foundation -framework UIKit -o /Users/XXXXXX/Library/Developer/Xcode/DerivedData/XXXXXXLibrary-egoqfplddstqvwaigwuiqfqplcax/Build/Products/Debug-iphonesimulator/UnitTests.app/UnitTests

    Undefined symbols for architecture i386:
      "_llvm_gcda_start_file", referenced from:
          ___llvm_gcov_writeout in XXXXXX.a(NSObject+SBJSON.o)
          ___llvm_gcov_writeout in XXXXXX.a(NSString+SBJSON.o)
          ___llvm_gcov_writeout in XXXXXX.a(SBJsonBase.o)
          ___llvm_gcov_writeout in XXXXXX.a(SBJsonParser.o)
          ___llvm_gcov_writeout in XXXXXX.a(SBJsonWriter.o)
          ___llvm_gcov_writeout in XXXXXX.a(XXXXXXReachability.o)
          ___llvm_gcov_writeout in XXXXXX.a(XXXXXX.o)
          ...
      "_llvm_gcda_emit_function", referenced from:
          ___llvm_gcov_writeout in XXXXXX.a(NSObject+SBJSON.o)
          ___llvm_gcov_writeout in XXXXXX.a(NSString+SBJSON.o)
          ___llvm_gcov_writeout in XXXXXX.a(SBJsonBase.o)
          ___llvm_gcov_writeout in XXXXXX.a(SBJsonParser.o)
          ___llvm_gcov_writeout in XXXXXX.a(SBJsonWriter.o)
          ___llvm_gcov_writeout in XXXXXX.a(XXXXXXReachability.o)
          ___llvm_gcov_writeout in XXXXXX.a(XXXXXX.o)
          ...
      "_llvm_gcda_emit_arcs", referenced from:
          ___llvm_gcov_writeout in XXXXXX.a(NSObject+SBJSON.o)
          ___llvm_gcov_writeout in XXXXXX.a(NSString+SBJSON.o)
          ___llvm_gcov_writeout in XXXXXX.a(SBJsonBase.o)
          ___llvm_gcov_writeout in XXXXXX.a(SBJsonParser.o)
          ___llvm_gcov_writeout in XXXXXX.a(SBJsonWriter.o)
          ___llvm_gcov_writeout in XXXXXX.a(XXXXXXReachability.o)
          ___llvm_gcov_writeout in XXXXXX.a(XXXXXX.o)
          ...
      "_llvm_gcda_end_file", referenced from:
          ___llvm_gcov_writeout in XXXXXX.a(NSObject+SBJSON.o)
          ___llvm_gcov_writeout in XXXXXX.a(NSString+SBJSON.o)
          ___llvm_gcov_writeout in XXXXXX.a(SBJsonBase.o)
          ___llvm_gcov_writeout in XXXXXX.a(SBJsonParser.o)
          ___llvm_gcov_writeout in XXXXXX.a(SBJsonWriter.o)
          ___llvm_gcov_writeout in XXXXXX.a(XXXXXXReachability.o)
          ___llvm_gcov_writeout in XXXXXX.a(XXXXXX.o)
          ...
      "_llvm_gcda_increment_indirect_counter", referenced from:
          -[SBJsonParser scanValue:] in XXXXXX.a(SBJsonParser.o)
          -[SBJsonParser scanRestOfString:] in XXXXXX.a(SBJsonParser.o)
          -[SBJsonWriter appendString:into:] in XXXXXX.a(SBJsonWriter.o)
          -[XXXXXX loginSuccessfulCallback:XXXXXXHttpResult:] in XXXXXX.a(XXXXXX.o)
          +[XXXXXXDataTank sharedDataTankManager] in XXXXXX.a(XXXXXXDataTank.o)
          -[XXXXXXDataTank processFiveHundredSeriesHttpResult:] in XXXXXX.a(XXXXXXDataTank.o)
          -[XXXXXXDataTank networkActive] in XXXXXX.a(XXXXXXDataTank.o)
          ...
    ld: symbol(s) not found for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've tried searching for the unfound symbols but google literally has 0 results.

I assume the static library is being built with something that the unit test target isn't but I cannot find it.

Does anyone have any suggestions?

Cheers

Tyler
  • 2,699
  • 4
  • 22
  • 31
  • 1
    This error generally comes when a framework isn't available. Here I'm not sure which framework is missing, but maybe you can try figuring out missing frameworks. – Sahil Khanna Oct 31 '11 at 04:53

6 Answers6

49

This worked for me well (catch the settings with bold):

enter image description here

Geri Borbás
  • 15,810
  • 18
  • 109
  • 172
12

If you don't need the code coverage, you can complete disable it by using the following settings, thus avoiding the attempted calls to those functions.

GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO
GCC_GENERATE_TEST_COVERAGE_FILES = NO
cahlbin
  • 1,039
  • 10
  • 17
4

llvm_gcda_start_file and co are added by LLVM compiler for code coverage and unit testing.

adding -lprofile_rt to Linker Flags in your project settings should solve this error. (older tutorial might suggest -lgcov which is for Xcode 3 and GCC)

According to Code Coverage on Xcode 4.4.1 "-lprofile_rt" is no longer required.

Community
  • 1
  • 1
Du Song
  • 577
  • 4
  • 12
  • 2
    I had the same problem and added the -lprofile_rt to Linker Flags, however that caused this error: `library not found for -lprofile_rt` – Josef Salyer Nov 30 '11 at 15:57
  • Haven't try with Xcode 4.3beta, but that did work in my 4.2, just try: 1) check if they exist: `/usr/lib/libprofile_rt.a /usr/lib/libprofile_rt.dylib /Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/libprofile_rt.a /Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/libprofile_rt.dylib` 2) check your project setting have the right path and etc... – Du Song Dec 01 '11 at 06:13
3

In my case, I had to add --coverage to the CMAKE_EXE_LINKER_FLAGS on Apple Clang Apple LLVM version 9.0.0 (clang-900.0.39.2). That seems to have fixed it. None of the above solutions worked.

The article below mentions it:

https://asmaloney.com/2017/01/code/code-coverage-of-unit-tests-using-qt-5-on-macos/

Sasanka Panguluri
  • 3,058
  • 4
  • 32
  • 54
1

In my case I was building for device. Switching to simulator worked like charm, but I have no clue why it is different. :-)

hfossli
  • 22,616
  • 10
  • 116
  • 130
-3

I Had the same error : Just add "libGoogleAnalyticsServices.a" into your files

Zubair
  • 5,833
  • 3
  • 27
  • 49