Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Undefined symbols for architecture i386" on unit tests

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

like image 551
hpique Avatar asked Aug 07 '12 14:08

hpique


2 Answers

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).

like image 193
hpique Avatar answered Oct 13 '22 05:10

hpique


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

like image 35
Jesse Gumpo Avatar answered Oct 13 '22 06:10

Jesse Gumpo