undefined reference for architecture i386 [duplicate] - iphone

This problem has been driving me crazy, and I can't work out how to fix it...
Undefined symbols for architecture armv7:
"_deflateEnd", referenced from:
-[ASIDataCompressor closeStream] in ASIDataCompressor.o
"_OBJC_CLASS_$_ASIDataDecompressor", referenced from:
objc-class-ref in ASIHTTPRequest.o
"_deflate", referenced from:
-[ASIDataCompressor compressBytes:length:error:shouldFinish:] in ASIDataCompressor.o
"_deflateInit2_", referenced from:
-[ASIDataCompressor setupStream] in ASIDataCompressor.o
ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
I think it has to do with:
ld: symbol(s) not found for architecture armv7
But I have added: libz.1.2.3.dylib and it's not helping, anyone got any ideas?

Common Causes
The common causes for "Undefined symbols for architecture armv7" are:
You import a header and do not link against the correct library. This is common, especially for headers for libraries like QuartzCore since it is not included in projects by default. To resolve:
Add the correct libraries in the Link Binary With Libraries section of the Build Phases.
If you want to add a library outside of the default search path you can include the path in the Library Search Paths value in the Build Settings and add -l{library_name_without_lib_and_suffix} (eg. for libz.a use -lz) to the Other Linker Flags section of Build Settings.
You copy files into your project but forgot to check the target to add the files to. To resolve:
Open the Build Phases for the correct target, expand Compile Sources and add the missing .m files. If this is your issue please upvote Cortex's answer below as well.
You include a static library that is built for another architecture like i386, the simulator on your host machine. To resolve:
If you have multiple library files from your libraries vendor to include in the project you need to include the one for the simulator (i386) and the one for the device (armv7 for example).
Optionally, you could create a fat static library that contains both architectures.
Original Answer:
You have not linked against the correct libz file. If you right click the file and reveal in finder its path should be somewhere in an iOS sdk folder. Here is mine for example
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib
I recommend removing the reference and then re-adding it back in the Link Binary With Libraries section Build Phases of your target.

I had a similar issue last night and the problem, was related to the fact that I had dragged a class from the Finder to my project in Xcode.
The solution was to go the the Build Phases tab and then the Compile Sources and make sure you drag the class to the list.

I had a similar issue and I had to check "Build Active Architecture Only" on each of the Project configurations (Debug, Release and Deployment) and in the Build Settings of the Target.

Another possible cause of "undefined symbol" linker errors is attempting to call a C function from a .mm file. In this case you'll need to use extern "C" {...} when you import the header files.
Linker error calling C-Function from Objective-C++

I had a similar issue with that. The class name after _OBJC_CLASS_$_ was actually my class. The reason was I didn't tick "Add to Target" when I drag the source code files into navigation list.
My solution was:
delete the class from the navigation list and choose "remove reference only"
drag the source code files again and make sure the tick box for "add to Target" is ticked. The tick box is just under "Copy if needed" and "Create group".

There is usually a alias without the version identifier that is linked to the current version, in this case libz.dylib is linked to libz.1.2.5.dylib. Use the base alias instead of the versioned one.

I had the same problem when I use admob library, I fixed it changing "Architectures" to "Standard architectures armv7, armv7s" without including 64-bit.

Under Target -> Build Settings -> Apple LLVM compiler language:
setting 'C++ Language Dialect' and 'C++ Standard Library' to Compiler default helped solve it.

I only added the libz.1.2.5.dylib to my project and it worked like a charm.
Steps -
Go to Build Phases.
Link Binary With library - use the '+' button to choose frameworks and libraries to add.
Select libz.1.2.5.dylib from the list.
Build and run.

I had a similar issue and saw errors related to "std::"
I changed Build Settings -> Apple LVM 5.0 - Language C++ -> C++ Standard Library
from libc++ (LLVM C++ Standard Library with C++11 support)
to libstdc++ (GNU C++ Standard Library)

If you have the flag -ObjC under your Target > Build Settings > Other Linker Flags and you're getting this issue, consider removing it. If you intentionally added it because you need to load some Obj-C code from a static library that wouldn't normally be loaded otherwise, IE, an Obj-C category, then you should use -force_load <path> instead of -ObjC.
<path> should be relative to your Xcode project directory. IE, if your directory structure looks like this:
iOSProject
+ iOSAPI.framework
+ iOSAPI
+ iOSAPI.xcodeproj
Then you should have this flag set for Other Linker Flags:
-force_load iOSAPI.framework/iOSAPI
If you want to include multiple libraries like that, then you should include a separate -force_load line for each of them.
-force_load iOSAPI.framework/iOSAPI
-force_load another.framework/another

Probably some classes are missing from your target. This usually happens when you rename/remove/add new classes files to your project. To fix add the newly added classes to some targets.
Select the class in the Project Navigator (right sidebar) , open the Utilities sidebar (right sidebar), from the Utilities select the File Inspector (file like icon), under the Target Membership tab tick your targets. This is all to avoid the "Remove reference" and add again with ticking "Add to targets" trick.
So: Select Class -> Utilities (File Inspector) -> Target Membership -> Tick the targets you want.

I have have multiple #interfaces in the .h file and hadn't yet included the all of the corresponding #implementation directives. Make sure that they are all balanced out.

Here's how I got this problem:
I added a .h, .m and NIB from another project by dragging them onto my project navigator. Xcode didn't add them to the Build Phases properly.
Check my answer because I had a similar problem that I was able to solve by doing some steps.

if you're dealing with the iOS5 upgrade, I found that for compiling a project written to target 4.3, I could just rename libz.1.2.3.dynlib in the Project Navigator to libz.1.2.5.dynlib and it compiled.
My iPhoneOS50SDK/usr/lib folder has no libz.1.2.3.dynlib--don't know whether it's a beta thing or just natural upgrade.

Go to your project, click on Build phases, Compile sources, Add GameCenterManager.m to the list.

This fixed my problem: The dependency I am using is not supporting armv7. So I had no other option than to remove it. Armv7 is used for only very old iphones anyway (like iphone 4).
Go 'Build Settings / All'
Set 'Valid Architectures' to 'arm64 arm64e'

I didn't find this suggestion here so here it goes:
if your project has more than one target (ie one for OSX and one for iOS) then you must link the relevant libraries for each target.. so for example in my case I needed AudioToolbox.. I had to add it once for OSX and once for iOS (under the frameworks folder, you must have a duplicate of each library for each target.. if you see only one.. then that's a red flag)

I was facing an issue with PJSIP libraries,
Tried the following in other linker flags in project and able to resolve the error:
-framework
Foundation
-framework
UIKit
Above linker flags are used in Siphone Project over github. These settings will help you resolve problems related to linking of C++ libraries.

Finally i've figured it out, I solved this issue by adding absent framework to target->Build Phases->Link Binary With Libraries

I once had this problem. I realized that while moving a class, I had overwritten the .mm file with .h file on the destination folder.
Fixing that issue fixed the error.

I received the 'Undefined symbols for architecture armv7:' error when trying to compile a project that had the target build setting for 'C++ Standard Library' set to 'libc++' (necessary as the project was using some features from C++ 11), and the project included a sub-project that had the same setting set to 'libstdc++' (or compiler default as it is currently).
Changing the sub-project's 'C++ Standard Library' setting to libc++ fixed it, but only after first setting the deployment target for the sub-project to 5.0 or above (5.0 is necessary for libc++).

I give you more suggestions that you can check when other common suggestions are not help.
If you link with other project(libxxx.a) you might sometimes meet strange problem which you can find the symbol with tools like nm but they just can not find the symbols in ld. Then you should check if the two projects are built in the same flags, some of them may affect the binary format.
check c++ compiler.
check c++ dialect setting.
check c++ runtime type support. (-frtti/-fnortti)
check if there is .a with the same name appears elsewhere, could be beyond the wanted file in the link path list. remove them.

I got this problem when I run app on iphone5s, it was solved by add arm64 to Architectures.

I had the same problem. I tried every thing from the huge list of answer but in the end my problem was:
I'm working with openCV so I need to combine C++ code in my code. To do this you should change the files which use objective-c and C++ to .mm
I didn't changed one file and this file has no connection to the C++ code but I had to change it.

I had this issue, when installing shareKit. It worked in the simulator, but not on the device. I removed -all_load from the Other Linker Flag and everything works fine in both simulator and iphone device.

In my case, I'd added a framework that must be using Objective C++. I found this post:
XCode .m vs. .mm
that explained how the main.m needed to be renamed to main.mm so that the Objective-C++ classes could be compiled, too.
That fixed it for me.

I use to face that issue when the module (file .m) is not in the target that I am working with.

For me the problem was that i forget to set value for my constants in the .m (implementation)
file const kFooKey = #"Foo";

I also added files through Dragging and Dropping. What I did, I removed references of all the files (Excluding frameworks) then added them again properly via Add Files To Project option, problem gone.

Related

iOS Project Update Xcode 4.2 to Xcode 4.5

In my Project I have done 90% development using XCode 4.2 (was only need to support 4.x,5.x), Now I need to Build for iOS 6 as well, so I switched to Xcode 4.5 & iOS 6. But I am facing lots of issues like framework error for "Sqlite3", "MobileCoreServices"
I have read below Thread but no success.
How to make Xcode 4.5 project work on previous version of Xcode?
Xcode linker Directory not found for option
Can anyone please tell me How can I compile "Sqlite3", "MobileCoreServices" frame work for ARMV7 & ARMV7S. I cant remove both from project, Since I have done almost :(
There are uncertainties for the exact reason behind this but your problem can be solved by any of the cases provided below.
Case 1 :
It may be due to any missing library like libsqlite3.dylib and libsqlite3.0.dylib or MobileCoreServices, so copy these files from any other computer and place these files in your computer.
Procedure:
1:Open xcode on the computer where these files exists, add libsqlite3.0.dylib in your project from link binary with libraries.
2: Right click on the libsqlite3.0.dylib and show in finder (same for MobileCoreServices).
3: Copy two files libsqlite3.0.dylib and libsqlite3.dylib and place on the same location on other computer where these files are missing.
Here you go, The problem may be solved in this way.
Case 2:
Reinstall XCode again it may work properly
Case 3:
Check this answer
Hope it helps you.
When click on your project in the project explorer, for each target, select that target. Then in the build phase, in the link with binary libraries, check your framework links.
If you have simple problem, you can remove and add the libraries again.
If the library is not built for arm7s, then goto target's archtecture, in the valid architectures, set it armv7 only. See if this remove the problem. if it is, then the frameworks needs to be build for armv7s.
Try deleting this framework.. add it once again from sdk 6.0 (target -> build phase)
Mangesh, Since you are updating the project to iOS 6, it is normal that your frameworks go missing some times. In order to add them, please go to build phases and then open the tab Link with binaries and add both the missing files as shows in the screen below.
It should help you add the libraries and you are ready to build it. If you are still facing problems, you can also add the Framework search paths (This will be your local path for the frameworks) for the project under the Build settings. And also please make sure that the framework paths are recursive.
In your .pch file, add the following
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
sqlite 3 and MobileCoreServices are available with ios 6.
Remove red references
Go in Targets properties -> Build Phases, section Link Binary With Libraries
Click on Add button and add libsqlite3.dylib & MobileCoreServices.framework.
If libsqlite3.dylib is not available in the list. Open your xcodeproj with a text editor then search and destroy hidden references to libsqlite3. And try again.
Vivien

This target might include its own product

File .../FaceDeFace.app depends on itself.
This target might include its own product.
File .../FaceDeFace.app depends on itself.
This target might include its own product.
I have done my project in os Snow leopard but now my os version also changed and it is now 10.7.3. This is installed in my Imac machine. This app start first in MacBook but now I want to develop it in IMac. But the above error is shown so what i have to do. Though I have change all of my certificate, and all provisioning profiles newly.
Please help.
Thanks i advance.
Select the target in your Xcode project and click the Build Phases tab. Look at the Target Dependencies list; the target's product should not be listed there, but it sounds like it may have been added to that list by mistake. Also check the other areas in that same tab -- you don't want your product listed in Copy Bundle Resources or Link Binary With Libraries, either -- you obviously can't use the thing that you're building as a resource or library to build the product in the first place. That's what Xcode seems to be complaining about.
Ran across this issue using Xcode 7 (beta 1) when trying to build a Static Library target. Here was the error message from the build output:
Unable to run command 'CopySwiftLibs libMyStaticLibraryName.a' - this target might include its own product.
(I substituted libMyStaticLibraryName.a above in place of the actual name of my static library.)
The problem turned out to be that this static library target had the Embedded Content Contains Swift Code build setting (EMBEDDED_CONTENT_CONTAINS_SWIFT) set to YES, when in reality there was no Swift code associated with this target. Setting this to NO in Xcode fixed the issue.
Static libraries cannot include Swift code, so if this build setting is set it causes the error, even if there is no actual Swift code in the target.
In my case, very simple, please delete Universal target, then add new target.
That's all
In my case my project had submodule inside, so commands
git submodule add submoduleURL
git submodule init
git submodule update
solved this issue.
I had the same problem, when podspec file was incorrect. My mistake was that I didn't specify .h and .m extensions for source_files. Because of that .xib files were added twice. This is a correct example:
s.source_files = 'YourTarget/Classes/**/*.{h,m}'
s.resources = ['YourTarget/Classes/UIComponents/**/*.xib']
See https://guides.cocoapods.org/syntax/podspec.html#source_files

XCode Compiler Error: ld: library not found for -loauth

I'm trying to use the Twitter libraries and after adding liboauth.a and adding oauthconsumeriphonelib to my header search path, I'm now down to 1 compilation error, which I can't seem to get rid of.
ld: library not found for -loauth
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
Anyone know what could be causing this?
Continuing to What Robin suggested You also need to set the Library Search Path. Right Click the Target File and Choose -- Get Info else you can also get the same by choosing Edit Actice Target Under the Project Tab in XCode. Look for Library Search Path and add this "$(SRCROOT)/Twitter+OAuth/SAOAuthTwitterEngine" Where Twitter+OAuth/SAOAuthTwitterEngine is the directory path for Twitter Library in project folder.
I hope this will fix the problem.
Well #Nefsu you need to add those libraries to your project by adding an existing framework and then giving the path of the libraries you want to use.
And if you have already added the libraries by drag and drop, than dont remove them just add existing framework by right clicking on groups and folders and add the libraries from the folder and you will be done
I discovered this HIGHLY misleading message while trying to upgrade to the new Google Analytics library.
In my case the problem was having TWO CONFLICTING COPIES of the library. They were in different folders but both were listed in my App's Library Build Paths (under Build Settings).
Moving all the deprecated library files out of the folder ended up doing the trick and made the mysterious error messages go away.

Xcode -- get force_load to work with relative paths

Some libraries require the -all_load linker flag when linking to an Xcode project. However, this leads to a linker error if there are symbol conflicts among libraries. The solution is to use -force_load, which effectively lets you use -all_load on some libraries, but not on others.
However, this in turn leads to a new problem, at least for me. Whenever I use -force_load with a relative path to a library, the linker always finds symbol conflicts between the library and itself. It appears that the linker thinks that the library with its absolute path and the library with its relative path are different libraries, and therefore finds conflicts between the library and itself.
I can avoid this by using an absolute path with the flag. But this is not a wonderful solution, as it is convenient to keep source code for libraries within my documents directory. But the path to the documents directory will be different on other machines.
Question: Can anyone get force_load to work with a relative path to the library?
EDIT: for background information, see this question
With Xcode 4, if you include the library project into your app project, then you can add this to the Other Linker Flags:
-force_load $(BUILT_PRODUCTS_DIR)/<library_name.a>
You still need the dependency, and you need to add the library in the Link Phase list of frameworks and libraries too.
EDIT: Apple now says as of some Xcode 4 release that you can simply use this linker flag: "-ObjC" to get libraries with categories to properly load. That flag is working just fine for me in Xcode 5. People are still up voting this answer, but I suspect that the -ObjC flag is the best solution now.
This worked for me. Like the above answers you still need to include the library in the project.
-force_load $(SRCROOT)/pathToLibraryFromProject/libname.a
For the path it's just the folders in your project that lead to where you put your library, for example BaseFoler/Subfolder/libName.a.

Cannot link in XCode when compiling for iPhone

somehow I managed to screw up my XCode project settings when compiling for the iPhone.
It fails when linking saying that
ld: warning: in /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/AddressBook.framework/AddressBook, file is not of required architecture
... (same for the other frameworks).
So the problem is it is trying to use the simulator framework when compiling for the iPhone.
When you look at the actual link command:
setenv IPHONEOS_DEPLOYMENT_TARGET 3.1
setenv MACOSX_DEPLOYMENT_TARGET 10.5
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.sdk
-L/Users/ben/development/xcode_output/Debug-iphoneos
-F/Users/ben/development/xcode_output/Debug-iphoneos
-F/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/
System/Library/Frameworks
-F/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.sdk/
System/Library/Frameworks
you can see that both the simulator framework and the iPhone framework path is provided.
How can I change that? I haven't found it anywhere in the settings.
The [FRAMEWORK_SEARCH_PATHS, -F] in the project settings is empty.
Maybe the problem is with linking in a static library.
The project settings for that static library contains a lot of duplicate settings.
There are always two identical settings (e.g. two Search Path blocks, two GCC-4.2 code generation blocks etc.) That doesn't look normal.
Regards
The only way I managed to solve this problem was by creating a new project and starting again :-(
ld: warning: in /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/AddressBook.framework/AddressBook, file is not of required architecture ... (same for the other frameworks).
Your building for device right? Not simulator?
Find the same framework, but under device. Check the whole file path when you import.
Check your target's Framework Search Paths. If there's an explicit path in there to the Simulator SDK, remove it.
I think the problem was that the static library I've linked in had two targets for the iPhone and for the simulator. I've changed that so that there is only one target and that seemed to have solved the problem.
Regards
Ben
I found when I added a framework to my project the "old way" by navigating to /Developer/platforms/.../Frameworks, it added the full path to the framework path search list in my target settings. This meant that all my frameworks were suddenly borked. Make sure that there is no full path in the search list and you should be able to fix your project without having to make a new one.
[Edit] And on further examination, I see this question was already answered by cdespinoza :)