1

I have some constant strings defined as extern const in header of MyClass.h:

extern NSString * const myConstant;

and in .m file:

NSString * const myConstant = @"Some Constant";

And I have a unit test file testing MyClass, it could test the class but when I use the constant in the unit test, the linker has a problem:

Undefined symbols for architecture x86_64:
"_myConstant", referenced from: ...

MyClass.m isn't ticked to be part of the Tests target, but I have the "bundler loader" and "test host" set up in Build Settings, so I thought I don't need to have MyClass.m part of Tests target, which works fine for the class itself.

Is there anything I did wrong with the extern const that it can't be found by the tests?

jscs
  • 63,694
  • 13
  • 151
  • 195
Heuristic
  • 5,087
  • 9
  • 54
  • 94
  • Yeah, you need to target MyClass.m to your test target. – rmaddy Nov 28 '17 at 03:08
  • @rmaddy Thanks for your comments, what I don't understand is that, although the class isn't part of test target, my unit test could find the class, but not the `extern const NSString` defined in the header and the .m file. – Heuristic Nov 28 '17 at 03:11
  • follow this link might be help: https://stackoverflow.com/questions/7330048/3-questions-about-extern-used-in-an-objective-c-project/7330190#7330190 – BuLB JoBs Nov 28 '17 at 09:15

0 Answers0