开发者

Multiple definition of linking error in C

开发者 https://www.devze.com 2023-03-27 02:16 出处:网络
开发者_运维问答 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:

开发者_运维问答 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"); }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消