Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extern in objective-C; do they behave differently than C?

I required to share a const value between two files; so rather than keeping a magical number I decided to use a const variable. So I created a global variable const int viewTag = 100; in my appDelegate.m Then accessed it as extern const int viewTag; but I got following linker error:

Undefined symbols for architecture i386:
"viewTag", referenced from:
  -[xxxViewController launchxxx] in libxxx_iPad.a(xxxViewController.o)
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

But the above thing is perfectly leagal in normal C,C++ env. can anybody throw some light?

Update: putting extern const int viewTag; in header and importing that header works, but I really don't want to do that for a single const int

like image 530
Prashant Rane Avatar asked Dec 04 '25 13:12

Prashant Rane


1 Answers

Try putting:

extern const int viewTag;

in appDelegate.h, then importing this header where you need access to viewTag.

like image 66
petert Avatar answered Dec 08 '25 14:12

petert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!