Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
like image 949
John Gallagher Avatar asked Feb 23 '12 00:02

John Gallagher


3 Answers

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
like image 71
W.K.S Avatar answered Nov 15 '22 21:11

W.K.S


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.

like image 36
John Gallagher Avatar answered Nov 15 '22 19:11

John Gallagher


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

like image 30
nielsbot Avatar answered Nov 15 '22 19:11

nielsbot