Reputation: 68
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 :)
Upvotes: 2
Views: 3332
Reputation: 16540
the problem is in the make file.
Note: 'all' should be the first target, not the second
Note: every target that does not create a file with the target name should be included in a .PHONY: target
Note: macros should be defined with ':=' not '=' because the '=' will result in the macro being re-evaluated each time it is invoked while the ':=' will result in the macro only being evaluated once.
Note: write the include of the dependency files like so:
(expand the 'ifneq' to include 'clean_all' and 'cleaning' and 'clean_doc'
# wrap with ifneg... so will not rebuild *.d files when goal is 'clean_all', etc
#
ifneq "$(MAKECMDGOALS)" "clean_all"
-include $(OBJ:.o=.d)
-include $(TEST_OBJ:.o=.d)
endif
Here is the root of the problem:
OBJ = $(SRC)/main.o\
$(SRC)/helper.o\
$(SRC)/init.o\
$(SRC)/basis.o\
$(SRC)/gauss.o\
$(SRC)/indices.o\
$(SRC)/eval.o\
$(SRC)/rhs.o\ <-- first instance of rhs.o
$(SRC)/visual.o\
$(SRC)/matrix.o\
$(SRC)/rhs.o <-- second instance of rhs.o
and this rule:
exec: $(OBJ) chkopts
-$(CLINKER) -o sim $(OBJ) $(PETSC_KSP_LIB)
contains an expansion of $(OBJ) where $(OBJ) contains the above error
Upvotes: 0
Reputation: 6876
Most likely your makefile or build scripts got messed up in the merge and it's linking the same file (rhs.o
) twice.
Upvotes: 1