Search code examples
cmakefileinclude-guardsmultiple-definition-error

make error: multiple definitions of... despite include guard


My compiler is giving me some very strange errors about multiple definitions of a function (or rather all functions in a specific .c file).

I am using include guards to prevent multiple declarations

My header files contain NO definitions, only declarations. No variables are defined in the file, only functions.

I double-checked: Only the .h file is included in other files. The .c file isn't included anywhere.

I am using the same method to include the rest of my code and I have no problems there. Because of this, I can give no minimum example of my problem because I can see no (relevant) difference between the files that are working and the files that are causing the compiler-problems.

The error first started occuring after merging two branches in git. Each of the two branches is compiling without trouble before the merge.

For now, I would be glad about any hint at all about where this problem could come from.

I would also provide my code and/or error-logs if anybody needs them. It's a rather long code though, so please feel free to ask in case you need it

the error message from make is

error message

src/rhs.o: In function `calculate_rhs':
/home/user/Desktop/WS5/src/rhs.c:15: multiple definition of `calculate_rhs'
src/rhs.o:/home/user/Desktop/WS5/src/rhs.c:15: first defined here
src/rhs.o: In function `evaluate_rhs1':
/home/user/Desktop/WS5/src/rhs.c:103: multiple definition of `evaluate_rhs1'
src/rhs.o:/home/user/Desktop/WS5/src/rhs.c:103: first defined here
src/rhs.o: In function `evaluate_rhs2':
/home/user/Desktop/WS5/src/rhs.c:140: multiple definition of `evaluate_rhs2'
src/rhs.o:/home/user/Desktop/WS5/src/rhs.c:140: first defined here
collect2: error: ld returned 1 exit status
make: [exec] Error 1 (ignored)

compiler command for rhs.o is

/usr/lib/petscdir/3.6.0/arch-linux2-c-debug/bin/mpicc -o src/rhs.o -c -fPIC -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -g3 -O0  -std=c99 -I/usr/lib/petscdir/3.6.0/include -I/usr/lib/petscdir/3.6.0/arch-linux2-c-debug/include    `pwd`/src/rhs.c

.h file is here: http://pastebin.com/Za37iWr7

.c file is here: http://pastebin.com/2mSzdZvT

The .h file is included only by the above .c file and the main-function

The headers of all other included (by rhs.c) files are:

Makefile: http://pastebin.com/LDj1e7xB

thanks in advance :)


Solution

  • Most likely your makefile or build scripts got messed up in the merge and it's linking the same file (rhs.o) twice.