Error message shows up when adding a class - objective-c

I have a class called PrimeNumber that I wrote recently, which worked absolutely fine with a Foundation Tool and a Mac application. However, trying to use it with an iPhone application fails. I added the .m and the .h files to my project and imported the .h file to my ViewController.h like this:
#import "PrimeNumber.h"
After trying to use a method declared in my PrimeNumber class and run my application, Xcode showed me two errors:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_PrimeNumber", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The PrimeNumber.h and PrimeNumber.m files are not red in the Project navigator. Product > Clean doesn't work either. Also, because my classes aren't declared in a framework, I do not think something like that can be the problem.
Can anyone tell me what I'm doing wrong? Thanks!
Edit: changing the class name to PrimeNumbers, then creating a new Objective-C class called PrimeNumber and copy-and-pasting the complete contents of .h and .m files of the PrimeNumbers class into the .h and .m files of the PrimeNumber class worked for me. Weird, but it worked. :)

You have to add it to the "Compile Sources" Build Phase as well.
Project -> Targets -> [Your Target] -> Build Phases -> Compile Sources (just drag PrimeNumber.m in there)

Related

_OBJC_CLASS_$_KeyboardViewController", referenced from:objc-class-ref in KeyboardPreferencesController.o

I am totally stuck with an error I am getting when trying to test project on the simulator.
Error looks like:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_KeyboardViewController", referenced from:
objc-class-ref in KeyboardPreferencesController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am building custom keyboard using keyboard extension and what I am trying to do is that in main application I am implementing settings view to modify keyboard like font change... so of course, it needs to be linked to extension header file KeyboardViewController.h
I have tried to add Other Linker Flags -> $(inherited) in both debug and release, also tried to switch Build Active Architecture Only -> YES but it also does not worked for me.
So is there any other solution for this because I can not find anything what will work for me.
Thanks in advance!
You need to compile and link the implementation file (KeyboardViewController.m?) into your target.
Use Xcode's File Inspector to make sure target membership is turned on. Look at the build phases to make sure the implementation file is included.
If those things are correct, look at the KeyboardViewController.m to make sure it actually has a #implementation section.

what does it means these errors in obj-c?

This is the first error:
"_OBJC_CLASS_$_BNRHypnosisView", referenced from:
objc-class-ref in BNRHypnosisViewController.o
(maybe you meant: _OBJC_CLASS_$_BNRHypnosisViewController)
ld: symbol(s) not found for architecture x86_64
The second is:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What does these errors mean?
Did you add #implementation for the class?
Have you imported a .m file instead of a .h file?
Errors come both form the linker (the pice that combines compiled code into one file) and says that he can't find all he needs to do that. He misses the class BNRHypnosisView (especially for 64bit)
do you have an m file for it?
does it come from library? e.g. cocoaPods
is the library 64-bit compatible?
==> you need to add and m file or a library with the #implementation of the class.
A Header file doesn't REALLY add it. The header file only makes it known to others that the implementation will be there.... if you want, think of headers as roadsigns with townies and implementations as towns

Xcode5: unit test linking errors

I seem to get this strange issue when testing an XCTestCase. I created a unit testing bundle, and set my main app as the "target"; now I can write tests against my Core Data NSManagedObjects just fine, but if I include anything else in my app that isn't an NSManagedObject, I get linking errors:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_iCloudListener", referenced from:
objc-class-ref in SLTestToDoWithRepeatInterval.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This only happens with non-NSManagedObjects. And iCloudListener is definitely in the Compiled Sources for the main app target. The problem is that though I can go and add this particular iCloudListener class into the test target -> Build Phases -> Compile Sources list, and that will make this particular linking error go away, but it introduces new ones since it starts giving linking errors about all the header files from the iCLoudListener class; and if I start adding those, they require more and more files, to the point where I have to include pretty much all of my code into the test target "Compile Sources" section.
Is there something I'm doing wrong here? Is there a setting which might be causing Xcode to ignore the non-NSManagedObject classes?
It's because the project inserted the core data's xcdatamodeld file in compile sources. Select your project -> Build Phases -> Compile Sources and delete projectName.xcdatamodeld file.
And also check if you have imported .m file instead of .h file, it also gives the same linker error.
Check all the #import codes.
And check if you have added core data frame work in library and imported core data .h file. Check for creation of NSManagedObject and import it's file.
Just try it and reply me if still any error.

Issues including C++ files with Objective C on iOS

I'm trying to include several different items from AudioCore, in particular, AQRecorder. This does, however, have dependencies on c++ code. Normally this is not an issue as I just rename my view controller to have the extension .mm and everything is great. But in this case, my dependency on AQRecorder.h indirectly goes to my main.m which is causing me great pain.
I've tried several different things including the following:
1) Changing all .m and .cpp files -> .mm files
Everything compiles perfectly, however, it can't deploy to my iOS device or simulator as I get this error when deploying to the device:
"Choose a destination with a supported architecture in order to run on
this device."
I'm using XCode 4.6 and my valid architectures are armv7 & armv7s (I've played with these but with no luck).
2) Tried using opaque pointers such as that in this guide:
http://philjordan.eu/article/mixing-objective-c-c++-and-objective-c++
I still run into the same issue where it won't compile.
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_AQWrappedRecorder", referenced from:
objc-class-ref in RTPPacketSender.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
My dependencies are as follows:
AQRecorder.h -> RTPPacketSender.h -> ActiveConversationViewController.h -> ConversationViewController.h -> AppDelegate.h -> main.m
Can anybody else recommend anything to try. I've quite literally spent all day debugging this issue with no luck.
Vince

Linker error when trying to use SmartfoxServer-framework with a Kobold-2D project

When trying to use the SmartfoxServer-framework inside a Kobold2d project we are getting the following error:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_CCAsyncObject", referenced from:
objc-class-ref in libcocos2d-extensions-ios.a(CCTextureCache+CCBigImageExtensions.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1
This happends due to the fact, that we have to include the -ObjC linker flag to have the categories loaded, which are defined in the SmartfoxServer-framework. I already read about the need to force-link a static library which contains categories here, but the SmartFoxServer-Framework isn't a static library.
Is there a way to force load a framework, so it includes all the categories without using the -ObjC linker flag? Or is there a convenient way to convert a framework to a static library? Any help is greatly appreciated!
Unless you are using CCBigImage, you can deselect the CCTextureCache+CCBigImageExtensions.h and .m files from the target.
Open the Kobold2D-Libraries project and browse to the group /Extensions/CCBigImage. From the menu choose View -> Utilities -> File Inspector. Select each file and uncheck the target checkbox in File Inspector. Now this particular class won't be compiled anymore and the error is gone.
The problem seems to be that this category uses a private class that's defined only in the implementation file. Unfortunately force loading the entire cocos2d-iphone-extensions project is not a solution because this brings up other errors.