First off, I have only really used Objective-c methods in my programming. I decided to do a couple of quick math calculations as c functions and then ended up needing them for multiple classes. So then I stuck the c functions in a separate .h file. This works fine until I try and import the .h file into more than one class. Then I get this error:
Duplicate Symbol *_myFunction* blah blah blah Linker command failed with exit code 1 (use -v to see invocation)
How can I use a c function in more than one class without this link error. I've tried just defining the functions in the classes I need them in, but it seems that even if they are different classes, I get this error if the function name is the same. I'm probably crazy here, but some help understanding would be great.
You should put declarations in the .h file, make them extern, and move definitions into a .c or .m file.
From this
myfunctions.h
int max(int a, int b) {
return a>b ? a : b;
}
Move to this:
myfunctions.h
extern int max(int a, int b); // declaration
myfunctions.c
int max(int a, int b) {
return a>b ? a : b;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With