5

I'm getting the following error only when I try to build the unit tests of an iPhone static library:

Undefined symbols for architecture i386:
  "std::terminate()", referenced from:
      -[ZipArchive dealloc] in libMyProject.a(ZipArchive.o)
  "___gxx_personality_v0", referenced from:
      Dwarf Exception Unwind Info (__eh_frame) in libMyProject.a(ZipArchive.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Building the original project works fine.

What can I be missing?

It should be noted that ZipArchive is a .mm file that references the libz.dylib framework, which is referenced both in the original project and in the test project.

Additionally, the usual Build Settings suspects have the following values:

Framework Search Paths: "$(SDKROOT)/Developer/Library/Frameworks" "$(DEVELOPER_LIBRARY_DIR)/Frameworks"

Other Linker Flags: -all_load -lxml2 - ObjC

Header Search Paths: /usr/include/libxml2

hpique
  • 119,096
  • 131
  • 338
  • 476

2 Answers2

7

I found the solution in this post.

For some reason that eludes me, the compiler needed the ZipArchive.mm file to be renamed to .m when the static library is used in another project (the test project, in this case).

hpique
  • 119,096
  • 131
  • 338
  • 476
  • 2
    follow this [issue](https://github.com/paypal/PayPal-iOS-SDK/issues/61). In project's Build Settings, add `-lc++` to Other Linker Flags can solve this problem if you don't want to rename .mm file into .m file. – likid1412 Oct 28 '14 at 06:05
4

This typically occurs for one of two reasons:

  1. You copied a framework or system header directly to your project folder instead of adding it with a reference through XCode
  2. You've installed multiple SDKs, and the wrong framework or header is being referenced. Most frameworks aren't "Developer" frameworks. SenTestingKit.framework is an example of a developer framework, UIKit.framework isn't. Oddly, there are two different places that Developer Frameworks exist. In the /Developers/~ folder in XCode, and also in the SDK Developers folder. The default behavior is to reference the framework in XCode's developer folder. To override this, enter "$(SDKROOT)/Developer/Library/Frameworks" in "Framework Search Paths". Or in the case of an imported header or library, go the corresponding field and add "$(SDKROOT)/..."

Make sure your search paths are the same correct for all Targets:Search Path

If you are using multiple SDKs, the wrong version of the Developer Frameworks could get added (like SenTestingKit). Manually enter the the correct one under Framework Search Paths with

$(SDKROOT)/Developer/Library/Frameworks

enter image description here

Jesse Gumpo
  • 4,777
  • 1
  • 20
  • 29
  • "Framework search paths" is empty on the original project and has value "$(SDKROOT)/Developer/Library/Frameworks" on the test project. If I remove that I get file not found on . – hpique Aug 07 '12 at 15:44
  • That's the configuration I already have on the test project (see question). If what you mean is adding it to the original project, then I just tested it and it still gives me the same error. – hpique Aug 07 '12 at 16:41
  • @hgpc your header search path should either be blank, or should reference the SDK folder: $(SDKROOT)/usr/include/libxml2 – Jesse Gumpo Aug 07 '12 at 20:51
  • Header Search Paths is blank on both projects. However, test projects need Framework Search Pats to point to "$(SDKROOT)/Developer/Library/Frameworks". In any case, the problem was something related to C++ code in static libraries. See my answer. And thanks a lot for trying to help. – hpique Aug 08 '12 at 09:53