After discussion: Here a description of what happened:
If you use gcc and you have two files (lets say f1.c
and f2.c
), and in both files you declare:
int myGlobalVariable;
Then the following will happen:
- When compiling
f1.c
intof1.o
, the object file will reserve space formyGlobalVariable
. - When compiling
f2.c
intof2.o
, the object file will also reserve space formyGlobalVariable
. - When you link both object files together, the linker will detect that there are two variables called
myGlobalVariable
and will merge these variables together.
Now it seems the nvcc
compiler/linker is not able to merge these variables.
The problem was, that the file ILS.h
declares <some type> p_instanceFragments;
. Because ILS.h
is included into both ILS.cu
and Consensus.cu
, you get this variable twice and nvcc
complains when it has to link the application.
The solution is to declare extern <some type> p_instanceFragments;
in ILS.h
and then to define <some type> p_instanceFragments;
either in ILS.cu
or Consensus.cu
(not in both).
The question What are extern variables in C has a rather extensive answer explaining all of this in detail.