Issue With Enabling ARC in COCOS2D - iphone

im following steps from
http://www.raywenderlich.com/23854/arc-and-cocos2d-v2-x
i can not set -fno-objc-arc for ccCArray.h ... even if i have set -fno-objc-arc to that file , compiler gives warnings and errors related to ARC... like
[WARN]warning: no rule to process file 'libs/cocos2d/Support/ccCArray.h' of type sourcecode.c.h for architecture i386
ARC forbids explicit message send of 'release'
what's wrong??

That is a header file, and no header files should be compiled. You normally include <file>.h inside your <file>.m.
To fix this, click on your project in Xcode, select your target and then check that this file is not present in the Build Phases tab.
Also make sure you don't have any other <file>.h in there.
Clean and build the project.

Related

undefined reference for architecture i386 [duplicate]

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.

lexical or preprocessor issue file not found occurs while archiving?

I am new to this iPhone development and i have almost completed my first application but when i try for creating an archive it gives an error lexical or preprocessed issue file not found But it runs fine in simulator and also has also tested on device. I have included SDwebimage architecture for lazy loading of image in table view.Can any tell me what is the issue?
Few things to try, Ensure the Framework and all it's headers are imported into your project properly.
Also in your Build Settings set YES to Always search user paths, and make sure your User header paths are pointing to the Framework.
Finally, Build->Clean and Restart Xcode.
Hope this helps !
UPDATE: According to SDWebImage's installation, it's required you make a modification to Header Search Path and not User header paths, As seen below.
Have you done this as well? I suggest slowly, re-doing all the installation steps from the beginning.
Spaces in a folder name in your header search path can cause this problem. Make sure the folders in your project do not have spaces in their names.
My project was building fine until I updated to Xcode 10.1. After the Xcode update, started getting Lexical or preprocessor Issue errors on build. Some XCDataModel header files could not be found.
This fixed the issue.
Go to Build Settings, Header Search Paths
Change the appropriate value from $(SRCROOT) non-recursive to recursive.
This ensures that subfolders are also searched for headers during build.
I had this same issue now and found that my sub-projects 'Public Header Folder Path' was set to an incorrect path (when compared with what my main project was using as its 'Header Search Path' and 'User Header Search Path').
e.g.
My main project had the following:
Header Search Paths
Debug "build/Debug-iphoneos/../../Headers"
Release "build/Debug-iphoneos/../../Headers"
And the same for the User Header Search Paths
Whereas my sub-project (dependency) had the following:
Public Header Folder Path
Debug "include/BoxSDK"
Release "include/BoxSDK"
Changing the 'Public Header Folder Path' to "../../Headers/BoxSDK" fixed the problem since the main project was already searching that folder ('../../Headers').
PS: I took some good screenshots, but I am not allowed to post an answer with images until I hit reputation 10 :(
I had this problem after changed project name. I used all the methods mentioned on the internet but still doesn't work. Then I realized that all the header files not found was from cocoapods, so I re-installed the cocoapods using pod install, and thus solved the problem.
Hope this could help.
In my case I was developing a framework and had a test application inside it, what was missing is inside the test application target -> build settings -> Framework Search Paths:
The value needed to be the framework path (the build output - .framework) which is in my case:
"../FrameworkNameFolder/" - the 2 points indicates to go one folder up.
Also, inside the test application target -> Build Phases -> Link Binary With Libraries:
I had to remove the framework file, clean the project, add the framework file again, compile and this also solved the issue.
The new version contain fix for this, feel free to update.
Or you can just replace
#include "iPhone_View.h"
with
#if UNITY_VERSION < 450
#include "iPhone_View.h"
#endif
Delete the unit testing from your project follow the below steps this will solve the issue.
select your project from the project navigator to open the project editor. From the target delete the test from the left side of the project editor and press the Delete key.
I know this is old, but I'm gonna chime in anyway because it may be useful to someone. If you can still see the file in Finder, then click on the file in your project and delete it, selecting "remove references" and not "move to trash".
Once the reference is removed, drag and drop the file from finder into your project again and it should sort itself out.
Just adding another thing that worked for me :
react-native link
Evidently my ReactNative files were no longer there. I could figure that out by clicking on
Build Phases -> Link Binary with Libraries ->
Then right clicking a file I knew was responsible for React, and clicking Show In Finder .
But nothing opened. So assuming the library went missing, I just ran the above command which relinked everything again.
Also if you havn't, try :
rm -rf node_modules/ && npm install
This happened to me after I renamed a file. For some reason it was still looking for the file with the old name. What I did was create the file that it was complaining about and added to the project. Then I did a Project->clean, then Project->Build and verified the error was gone. Then I selected the newly added files and deleted them. This removed all references and I no longer see the error.
I fixed mine. The fb sdk downloaded (from my browser) as 'FacebookSDKs-iOS-4.22.0' -- I just had to rename the folder to FacebookSDK. So now in Build
Settings --> Framework Search Paths
the path looks something like /Users/.../Documents/FacebookSDK (where as before it was /Users/.../Documents/FacebookSDKs-iOS-4.22.0)
Hope this helps!
For what it's worth, my problem was completely unrelated to the error Xcode was giving. I stumbled onto a solution by deleting the .h reference, compiling, adding the reference back and compiling again. The actual error then became evident.

Command /Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1

I'm trying to do an application reading pdf using pdf kit in Xcode 4.3 but it gives me the following error
ld: duplicate symbol _OBJC_METACLASS_$_OverlayManager in /Users/dt4it/Library/Developer/Xcode/DerivedData/MyPdf4-bmkjglhhvneluqcbwpceiqjvdcmq/Build/Intermediates/MyPdf4.build/Debug-iphonesimulator/MyPdf4.build/Objects-normal/i386/OverlayManager-D0866CFD31A05E68.o and /Users/dt4it/Library/Developer/Xcode/DerivedData/MyPdf4-bmkjglhhvneluqcbwpceiqjvdcmq/Build/Intermediates/MyPdf4.build/Debug-iphonesimulator/MyPdf4.build/Objects-normal/i386/OverlayManager-B31AE7412100AF6D.o for architecture i386
Command /Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1
any help please ??
Project Settings > Under "Targets", select your project > Build Phases >
open "Compile Sources" and "Copy Bundle Resources". Check if any files are listed in red color. If so , just delete it. Then clean and run.
Worked for me.
Do a clean. product > clean . Terminal purge & reboot didn't work for me, cleaning did.
I had this same error and nobody seems to have an answer on StackOverflow that actually works. My problem was when I tried copying a project that was in a team repository. Turns out, in the ignore file, all files with the extension of *.pch were ignored from repository commits. This means that when I went to pull the project from the repo, the .pch file was missing, thus throwing this error.
Fortunately I had a copy of the project still and was able to just copy the .pch file over and I was then able to compile just fine.
Hope this helps?
Go to target preferences, summary tab, find "Deployment target" and increase it.
deleting ~/Library/Developer/Xcode/DerivedData helped me.
reference : link
I face this problem too. And ofc I looked for help in SO instead of use the common sense and check the error message.
The last part of the error message was the same as you.
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 11
But few lines above I found:
In file included from /Users/Ricardo/Documents/XCode/RealEstate-Finder-v1.2/RealEstateFinder/RealEstateFinder/RealEstateFinder-Prefix.pch:26:
/Users/Ricardo/Documents/XCode/RealEstate-Finder-v1.2/RealEstateFinder/RealEstateFinder/Config/Config.h:174:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
http://www.myserver.com/apps/mobile/rest.php?id=12
Which points to my Config.h file.
Happy coding!
You have accidentally included the .m file OverlayManager instead of the .h file inside the actual OverlayManager class itself! Basically, he compiler already knows to compile the .m file, but when you #import it, the compiler tries to include it inline with that same source file, thus generating duplicate symbols. But your case is unique, seeing as you are #importing the .m of the actual class' .m file! It's recursively compiling your OverlayManager class.
The same thing happened to me and i found that i forgot to put the " at the end of the
#import "CPDConstants.h
so instead
#import "CPDConstants.h"
For me this error appears after cloning the project from a repository. Someone removed a white space from the projects name (renamed: "The Project" to "TheProject") which caused some Build Settings errors to unvalid paths.
Sometimes reading the whole error logs is not a bad idea....
Try this - click on the name of your project on the list of files/folders on the left in Xcode (at the very top of the list). Look at the "Targets" section on the left-hand side of the window to the right. Likely, there's two listed with the second being a "test" item. Right-click on that item and select "delete". Then try to run the project again.
This problem usually occurs when there are more than two versions of XCode are installed in which different Swift versions incorporated for Ex. XCode 6.4 and XCode 7.3 are installed which are running Swift 1.2 and Swift 2.0. By mistake you tries to compile code with icorrect version for Ex. your project in in Swift 1.2 and you tries to compile it with xcode 7.3. In this case drive data stores information for swift version but when you tries to compile code with correct XCode it gives error.
To resolve this
Delete drive Data
a. In Xcode select preferences
Once preferences are open click on Location tab and click on the arrow in front of the 'Drived data' path. It will open drived data folder
Quit Xcode
Delete all drive data.
reopen the project in correct XCode error is fixed !!!!!!
The thing to consider here is the *.pch file. If you're doing an include from an external library then you have to make sure you're doing the include after #ifdef OBJC and before #endif. If you try to do your include outside this condition this might be a cause of the compiler error.
Had this happen in a team using git. One of the team members added a class from an external source but didn't copy it into the repo directory. The local version compiled fine but the continuous integration failed with this error.
Reimporting the files and adding them to the directory under version control fixed it.
I too had this error. But in my case, and I'm sure I'll be a one off here, I had accidentally deleted main.m when I hit the delete key after the app had crashed on the iPhone simulator.
After a crash, Xcode shows the main.m file and when I had hit delete, I had accidentally deleted the main.m file from my project, as it is easy to do when a file name is highlighted, not the code in the detail view.
Main.m normally resides in a group or folder named supporting files in the project file manager. I had not noticed this happened until it failed to build and run next time around and then I had to re-read the error message more closely and saw it said main.m is missing.
Thank you all for your input, but just in case there is someone in my position check for any file names in red showing missing files and restore them from a backup if you have it.
Adding the missing files(files in red color in Xcode->target->Build Phases->compiled sources) to the target folder resolved the issue for me.
My problem was that under Build Phases -> Compile Sources, I added a compiler flag for a file, but I had misspelled it. It was supposed to be:
-fno-obj-arc
to show that this file does not use ARC.
May be it will be helpful for someone:
I had the same error after deleting several files from project. After having deletes committed in git repository this error has gone...
Xcode 8
#Spoek's answer is right,
But If you won't find file in red color, then find the one with low opacity,
see this image,
The first one is there but second one is note there, so delete it.
My case, I fix it by:
Go to Build Phases and check Compile Sources files, check if it has duplicate file, just keep one.
In my case it was a duplicate Swift Flag entry inside my Target's Build Settings > Other Swift Flags. I had two -Xfrontend entries in it.
In my case,
Build Phases -> check Compile Sources files -> delete xxx.swift files that xcode says "can't find "xxx.swift"
This happened to me and it took me an hour to find it. In my case I had typed too fast and did:
[seld method];
instead of:
[self method];
Seriously! I don't know why it didn't catch this in a more recognizable way. But it was of course looking for a class called "seld".

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.

.dylib linked in Debug, not found for Release for iPhone in XCode

So I have included the libxml2.2.dylib library into my iPhone XCode project to create some Xml and XPath parsing utilities. When I compile and run in Debug mode for both the Simulator and Device I have no problems, however, When I switch to Release mode I get...
"error: libxml/tree.h: No such File or directory" as well as other similar errors for the following .h files.
#import <libxml/tree.h>
#import <libxml/parser.h>
#import <libxml/HTMLparser.h>
#import <libxml/xpath.h>
#import <libxml/xpathInternals.h>
What do I need to do to ensure the libary is included and linked to the Release build?
An error on the .h is a compile-time error with your Header Search Paths, not a .dylib or a linker error.
You have to ensure that ${SDK_DIR}/usr/include/libxml2 is in your Header Search Paths in your Release configuration.
i was going around in circles this morning with this same problem with xcode 4.
again as described exactly above, it builds with fine with
Schema >
Build Configuration
--> Debug
but fails when switching it to Release
tried numerous cleans and
adding ${SDK_DIR}/usr/include/libxml2 or
$/usr/include/libxml2
and triple checking Header Search Paths / checking the recursive check box all to no avail.
Was about to start a new project when ....
I managed to resolve it by adding
${SDK_DIR}/usr/include/libxml2 to the User Header Search Paths
do make sure that libxml is included in your project , that was the one that caused the problem for me.
add libxml2.2.7.3.dylib to linked libraries