Why am I getting "_OBJC_CLASS_$..., referenced from:" linker error when I have correctly linked frameworks? - objective-c

My Problem
I getting "_OBJC_CLASS_$..., referenced from:" linker error when compiling some Xcode projects (it happens in both iOS and Mac projects) I have correctly linked frameworks and imports.
Setup
One application target
One test target
All frameworks linked correctly
On compile I get the following linker errors:
"_OBJC_CLASS_$_JGCountdownTimer", referenced from:
objc-class-ref in JGCountdownTimerTestCase.o
for many classes that are used in tests.
What I've Tried
Checked that imports are all present
Removed all non standard frameworks
If I compile a class for both the test target and the app target it fixes the issue. But then I get other warnings from the compiler.

I faced a similar problem. I got the linker error:
_OBJC_CLASS_$_MyClass
The problem was that I had declared an #interface for MyClass but had not declared its corresponding #implementation.
The fix was to simply add
#implementation MyClass
#end

Quick Answer
Copy and paste the following line into your build settings:
GCC_SYMBOLS_PRIVATE_EXTERN = NO
In the target build settings look for "Symbols Hidden by Default". For the Debug configuration you want "No".
I've had this problem on and off for many months and I've just discovered why.

Not sure if this could be the problem, but with the new compiler, any obj-c that aren't explicitly referred to/invoked will not be linked from libraries. This causes problems when you implement categories in libraries for example.
Try adding '-ObjC' to 'additional linker flags' in the build settings panel for your target. shrug

objc_class_$textfieldvalidator referenced from
Compile doesn't include those copied files in its compile list. To fix this error
select the file or folder, then go to the Build Phases panel and open the Compile Sources step, then click the + button and add them all file or folder.
Right click on a project folder, click "Add Files to ...", select the file(s), click the Options button and select the target, then click Add.

Related

Calling Objective-C from Swift class causing linker errors

I'm trying to use RFDuino Objective-C library in Swift. It all sounds simple, I have called Objective-C from Swift classes before, no problem. This time however I hit the brick wall.
Created header file. Added header files to it. Swift can see the classes no problem. Project compiles fine.
The problem during build appears just after I try to call any of Objective classes
for example:
override func viewDidLoad() {
super.viewDidLoad()
let rfDuinoManager: RFduinoManager = RFduinoManager.sharedRFduinoManager()
}
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_RFduinoManager", referenced from:
__TMaCSo14RFduinoManager in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Im not sure what Im missing here.
Link to the project here.
https://www.dropbox.com/s/rza1ce01g4q5lp6/SmartHomeHub-stackoverflow.zip?dl=0
Thanks in advance for help. Honestly loosing hope now and considering rewrite whole library to Swift
The problem is how the rfduino folder was added to the project. So
Remove rfduino folder (selecting rfduino folder in the project navigator panel on left and hit delete button, but when it asks to move it to the trash or just remove references, choose "remove references".
Your bridging header has an absolute path reference, I'd suggest removing that altogether by selecting it in build settings and hitting delete button:
Re-add rfduino files back to the project, this time, under "added folders" option, choose "create groups" rather than "create folder references". If you want it to prompt to create proper bridging header for you, don't select folder, but select the individual files:
Also make sure that SmartHomeHub is checked below.
If you do that properly it will ask you to create bridging header automatically:
Go to this new bridging header and add your import lines again:
This is a linker error, not a compiler error. Are you sure the RFduino class (source or library) is included in your project (open the project membership panel on the right in Xcode and make sure the box is checked to include the library in your target).
If it is included, make sure it has x86_64 code compiled into it. It might be an iOS library and is just compiled for ARM. You can check by finding the binary and running lipo on it from the command line.
lipo -info [name of RFduinolibrary.a(dylib,whatever)]
it should show x86_64 as an architecture, ala:
Architectures in the file are: i386 x86_64
"The OPN [Debug] target overrides the OTHER_LDFLAGS build setting". This was the main issue. After adding $(inherited) in new line in other linker flags solved my issue.
For me, Removing all the files in 'derived dir', removing reference to the frameworks in my project and connect again and etc didn't work anymore. Only worked to me is to set 'Build Active Architecture Only' to 'YES'.

Objective C Linker Error: Undefined Symbols

What does it mean to have undefined symbols?
There are no errors in the code files themselves and I am NOT using any external libraries.
I DID add a typedef NS_ENUM prior to this linker error occurring.
Where do I add this -v to see invocation?
Here is the error message:
Undefined symbols for architecture x86_64:
"_OBJC_IVAR_$_UIViewController._parentViewController", referenced from:
-[PEPI_LessonController setParentViewController:] in PEPI_LessonController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
"Undefined Symbols"
Building source code files to an executable file consist of at least two steps:
Compile the source code files to intermediate binary files (often called xyz.o).
Link the intermediate binary files to the final executable file.
The error message "undefined symbols" is a linker message. It may appear even though the compilation process was successful without notice. The linker organizes final memory address relations and it replaces symbols that the compiler had to assume they would be valid later, if all parts of the code would be available. Without this, no modularization would be possible at all.
-v to see invocation
If you build your application in Xcode, then Xcode calls all the compile and link commands for you (CompileC, Ln, Clang ...). But remember that a typical IDE runs only the commands you could run by yourself in the shell. Theoretically, you could develop big applications only in a text editor and a shell. So I suggest take some time and try to copy paste some commands listed in the Xcode build report to a shell :-) You'll learn a lot about the backgrounds. Therefore, in my opinion, -v to see invocation is used while invoking the command in the shell - or in the build settings, if you wish permanently more information.
"External libraries"
Finally, try to clarify "external libraries". To look at the most simple example: even if you write a simple C program and you want to know something trivial like the length of a string, you'll include <glibc.h>. Now this is an external library. It's external to your program code. Are you sure you haven't included external libraries?
Solving linker problems
Linker errors are often confusing and somehow difficult, because details of the linked modules tend to be out of sight. You may find many hints if you enter the error message in a search engine. For example, have a look at here:
Undefined symbols for architecture armv7: "_SCNetworkReachabilityCreateWithAddress"
Even if all components are found for linking, all paths are known etc, they may have the wrong version or else.
It means it can't find the property parentViewController and method setParentViewController when linking your object files files. The most common cause for these types of errors is not linking a library or framework in your projects target. UIViewController is part of UIKit so I'd be surprised if it's not already linked. Is this an OSX project and your trying to use UIViewcontroller instead of NSViewController?
In my case I had forgotten to add the .m file to all the same targets as the .h and that's what caused this issue. In case it helps anyone thought I'd mention here... double check your target memberships!

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.

Duplicate symbol _OBJC_CLASS_$_Facebook

I'm building an ARC iphone app, and about to integrate the addThis ios library.
I get the following error:
ld: duplicate symbol _OBJC_CLASS_$_Facebook in /Users/mars/Desktop/Pst/trunk/Pst/ThirdPartyLibs/FBConnect/FacebookSDK/FacebookSDK.framework/FacebookSDK(Facebook.o) and /Users/mars/Library/Developer/Xcode/DerivedData/Pst-bqmphjiqldalzsankfvxugsurcdj/Build/Intermediates/Pst.build/Debug-iphonesimulator/Pst.build/Objects-normal/i386/Facebook.o for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've double checked with my Compile Resource, and only 1 facebook.m is present.
I've also put "-fno-objc-arc" in my compiler flags for those library files because they are built without ARC
Any help would be really appreciated!!
I've got the same error when followed the instruction to drag ThirdPartyLibs to my project. It had added both FBConnect and FacebookSDK to my project.
If you open the AddThisDemo project, which comes with the library, you will see that only FacebookSDK and DeprecatedHeaders were added (not entire FBConnect). I have recreated this structure in my project and that had solved my issue.
Hope that helps!
For anyone with this issue but these answers are not helping: if you created one custom class and called it Facebook.h/.m, just change its name and after it, no more linkage errors.
You have a #import "facebook.m" in one of your files where you should have put #import "facebook.h".

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.