"Undefined symbols for architecture i386" on unit tests - iphone

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

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

This typically occurs for one of two reasons:
You copied a framework or system header directly to your project folder instead of adding it with a reference through XCode
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:
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

Related

Swift 2 / iOS 9 - libz.dylib not found

I'm using some external codes from google in my new Swift 2.0 project that required "libz.dylib" in earlier versions. After updating to the new Xcode / the new SDK.
Xcode is now unable to import the libz.dylib and throws some errors
Undefined symbols for architecture i386:
"_deflate", referenced from:
+[GAICompressionUtil gai_dataByCompressingBytes:length:compressionLevel:mode:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
"_deflateEnd", referenced from:
+[GAICompressionUtil gai_dataByCompressingBytes:length:compressionLevel:mode:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
"deflateInit2", referenced from:
+[GAICompressionUtil gai_dataByCompressingBytes:length:compressionLevel:mode:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
"_inflate", referenced from:
+[GAICompressionUtil gai_dataByInflatingBytes:length:isRawData:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
"_inflateEnd", referenced from:
+[GAICompressionUtil gai_dataByInflatingBytes:length:isRawData:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
"inflateInit2", referenced from:
+[GAICompressionUtil gai_dataByInflatingBytes:length:isRawData:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When looking through the available packages in the "build phase" settings I can find "libz.tbd" which seems to be the replacement for the libz.dylib. When importing this lib the linker error stays the same but I get this additional warning:
warning: skipping file '/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/usr/lib/libz.tbd' (unexpected file type 'text' in Frameworks & Libraries build phase)
What to do?
I had the same problem. I found some kind of way around.
Go to Build Phases >Link Binary with Librairies > + > Add other
Once in the file selection window do "CMD"+Shift+G (Go to folder) and type /usr/lib/
From /usr/lib you can add : libz.dylib and more...
Compile and have fun
libz.dylib is now found under libz.tbd
quote from the Apple developer forums:
For those who are curious, the .tbd files are new "text-based stub
libraries", that provide a much more compact version of the stub
libraries for use in the SDK, and help to significantly reduce its
download size.
Hopefully more documentation will be coming soon.
edit
To clearify it, i will cite Guitz answer with the updated Content
Go to Build Phases >Link Binary with Librairies > + > Add other
Once in the file selection window do "CMD"+Shift+G (Go to folder) and type /usr/lib/
From /user/lib you can add : libz.tbd and more...
Compile and have fun
Remove all dynamic libraries (dylib) from the linking with binaries phase. It will find these libraries on its own.
I have this problem in objective-c project.ios9.1,xcode7.1
1.Go to Target> Build Phases >Link Binary with Librairies > +
2.select libz.tbd and add it
It worked for me
libz.dylib is the dynamic lib for Zlib, You can install Zlib from here http://zlib.net/
You can also add the lybz.dylib from "Other Linker Flags" in the Build Settings by adding the argument -lz.
I had to do this because, using the method where you reference the library from /usr/lib, when I deployed my app to our testers the .dylib library could not resolve and caused the app to crash on launch.
You can add libz.1.dylib from location:/usr/lib/
Go to Build Phases >Link Binary with Librairies > + > Add other
Once in the file selection window do CMD+Shift+G (Go to folder) and type /usr/lib/
From /user/lib you can add : libz.1.dylib
It worked for me.
Meanwhile you can use previous SDK. This is my answer for libsqlite3:
https://stackoverflow.com/a/30981161/627794
Edit: (link content added)
Open terminal, type (change to your desired library, e.g. libz)
locate libsqlite3.dylib
You'll find several files like these:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libsqlite3.dylib
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libsqlite3.dylib
Go to your project's setting -> Build Phases -> Link with Binaries. Add BOTH files by clicking +, then Add Other. Hit Cmd-Shift-G, and copy-paste the file path. Click Open.
If you install sqlite3 using macports, remove /opt/local/lib from Library Search Path in Build Settings.

Correct way to use a private library in objective c?

I downloaded a collection of private libraries from this link. When I click download I get all frameworks. So these are only header files not the .framework files that are available in Xcode. So I linked them by the usual method of going to build phases, in it I go to link binary with libraries click on + and choose the header files from a framework (preferences framework in my case). After these files are added to my project I try to make an object from one of the libraries and try to call their instance methods. When I try to execute this program I get this error. I get this whether I run it on the device or simulator.
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_DevicePINController", referenced from:
objc-class-ref in UAViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1
(use -v to see invocation)
DevicePinController is a part of a private framework preferences.h.I am trying to make an object of it UA
EDIT: I tried using other framework headers such as bluetooth and I get this error in all.
EDIT: I tried adding the entire framework to the project instead of adding individual header files.Now the error is
d: framework not found BluetoothManager
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You'll need to actually build the framework. You can't just link against a header file; that doesn't make sense.
Try adding all the .m files in the Preferences folder as Compile Sources, and remove the header file from Link Binary with Libraries.
Added: I realize now this answer is incorrect. The files OP is trying to use are not a library, but header files from Apple's private frameworks. Here's a related answer: https://stackoverflow.com/a/13388225/893113

iphone, setting up application tests error _OBJC_CLASS_$_MyClass undefined symbols

I am trying to set up application tests for my iOS application. I am using the following article as the basis of what I am doing:
http://cocoawithlove.com/2009/12/sample-iphone-application-with-complete.html
So I can created the additional targets that I need. I now have 3 targets:
-The original target
-The tests target
-The duplicate target
I have added the original target as a target dependency to my test target. I have then added the test target as a target dependency on my duplicate target.
However, whenever I try to reference any of my classes in my test cases I get:
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_MyClass", referenced from:
objc-class-ref in MyApplicationTests.o
"_OBJC_CLASS_$_AnotherClass", referenced from:
objc-class-ref in MyApplicationTests.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is there another location which I need to set up some sort of dependency to tell my Tests target that it is dependant on the original target?
Cheers
So I found the solution to this issue at:
http://twobitlabs.com/2011/06/adding-ocunit-to-an-existing-ios-project-with-xcode-4/
You need to do the following to avoid this issue:
Go back to your app target (not the test target), set the Symbols Hidden by Default build setting to NO
Now there is no need to add any source files to the Compile Source for the test target as long as the original target is set as a dependency.
You have to include the .m file for any of your classes that you reference from your test code in the list of compiled sources for your test target. From the error message you provided, that sounds like your problem. In XCode 4.2 you can add a compile source to a target by selecting your project in the project navigator, then selecting your test target, the Build Phases tab, and expanding the Compile Sources section. Click the "+" below the Compile Sources section and then select your class' .m file.

Adding Reachability class fails when I am trying to build

I have added the SystemConfiguration framework. I am deploying against targets from 3.2 and higher. Have I forgotten to add something?
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_Reachability", referenced from:
objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Okay, the clues are all in the error report you have posted.
While linking (the message is from the linker ld) which occurs after compilation of all the symbols across your project, the message is saying
"In AppDelegate, you have referenced a class object called Reachability"
"_OBJC_CLASS_$_Reachability"
and as far as the linker is concerned Reachability is undefined.
So, check that Reachability is being compiled in your project. The are a couple of ways to do this. Perhaps the most clear way is to
1 select the project file in the navigation pane
2 select the target
3 select Build Phases
4 Expand the Compile Sources section
*Now check the list of sources that will be compiled for your missing class, in your case Reachability.m
If it is missing, use the + button to add the file to the target.
Another way is to
1 select the file you think is not being compiled
2 open the utilities panel
3 select the file inspector tab
There will be a checkbox for each target in your project and you can easily see if your .m file is being compiled for each/all targets or not.
You might have forgotten to include the Reachability classes in your project!
I had a similar problem when I upgraded to the newest version of Mixpanel. The error read:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_CTTelephonyNetworkInfo", referenced from:
objc-class-ref in Mixpanel.o
You can follow Damo's solution until the last step, and then instead of expanding the Compile Sources section, you have to expand the Link Binary With Libraries section instead, and add the CoreTelephony.framework source which contains CTTelephonyNetworkInfo.
You can read more about the CTTelephonyNetworkInfo class reference on Apple's official website here: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/CTTelephonyNetworkInfo/Reference/Reference.html

Iphone-exif 0.91 not working when I add it to my project, gives error ".objc_class_name_EXFJpeg", referenced from:

When I add libiphone-exif.a to snapandrun in objectiveflickr I get this error:
".objc_class_name_EXFJpeg", referenced from:
literal-pointer#__OBJC#__cls_refs#EXFJpeg in SnapAndRunViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I do not know what this means, I follow the guide to add it, add all of the .h files and the libiphone-exif.a
Is there something special I have to do?
It sounds like you didn't add the library properly. It is a static library, not an Objective C or data file, so simply adding it to the project isn't enough. All that will happen is that it gets copied into the application bundle, when it needs to be statically linked into the executable. You have to open your targets and add the .a file under "Link Binary With Libraries".
I downloaded the source from the svn project from google and drag and drop into my project.
Clicking the target and marking the static lib as "weak" type instead of "required" made no difference.