How to prevent multiple definitions in C?
Posted
by Jordi
on Stack Overflow
See other posts from Stack Overflow
or by Jordi
Published on 2009-03-23T09:46:00Z
Indexed on
2010/03/18
23:31 UTC
Read the original article
Hit count: 208
c
|multiple-definition-error
I'm a C newbie and I was just trying to write a console application with Code::Blocks. Here's the (simplified) code: main.c:
#include <stdio.h>
#include <stdlib.h>
#include "test.c" // include not necessary for error in Code::Blocks
int main()
{
//t = test(); // calling of method also not necessary
return 0;
}
test.c:
void test() {}
When I try to build this program, it gives the following errors:
*path*\test.c|1|multiple definition of `_ test'| obj\Debug\main.o:*path*\test.c|1|first defined here|
There is no way that I'm multiply defining test (although I don't know where the underscore is coming from) and it seems highly unlikely that the definition is somehow included twice. This is all the code there is.
I've ruled out that this error is due to some naming conflict with other functions or files being called test or test.c. Note that the multiple and the first definition are on the same line in the same file.
Does anyone know what is causing this and what I can do about it? Thanks!
© Stack Overflow or respective owner