I am developing an application in C. I want to use a local function with the same name in more than one source files. Let me simplify the issue:
In hell.c
void myLocalFunc(){ printf("Hello hell\r\n"); }
In world.c
void myLocalFunc(){ printf("Hello world\r\n"); }
Because they are local functions only, i dont declare them in header files. But when i compile the project, it gives me "Multiple definition of 'myLocalFunc'" error message and also this one: "Multiple definition of 'myLocalFunc' (first defined here)".
What is my mistake here?
Replace it with
static void myLocalFunc(){ printf("Hello world\r\n"); }
Or, if you're using C++, you can also use an anonymous namespace like this:
namespace {
void myLocalFunc(){ printf("Hello world\r\n"); }
}
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