I’ve built a static library, to be linked in my iPhone apps. This library uses some global variables and functions, like in C. My problem is, when using for example:
extern
void do_stuff (const int a)
{
return a*a;
}
extern const int a_variable;
extern const int an_array[DEFINED_VALUE];
When I use this function, or access these variables, anywhere in my code, the compiler tells me
“_do_stuff” referenced from:
-[Object testMethod] in tests.o
“_a_variable” referenced from:
-[Object testMethod] in tests.o
“_an_array” referenced from:
-[Object testMethod] in tests.o
Symbol(s) not found
Collect2: Id returned 1 exit status
Has anyone ever faced this problem before? I know I’m doing something stupid, I’m missing some key Objective-C or C concept, but I can’t really see what. So I was hoping someone could help me. Thanks in advance.
These are linker errors, telling you that the referenced entities can’t be found. Probably this means that you haven’t added your library to the project.
As an aside, you probably should distinguish between the place where you declare these things, where they should indeed be declared as
extern, and the place where you define them, where they shouldn’t be. That is, you might have a header file that includes:And then an implementation file that has something like:
As another aside, calling something
a_variablewhen it’s actually aconstis a bit misleading!