Reputation: 26
I am trying to make a project I've been working on use CUDA. At the moment it has four build configs, two (release and debug) which define a compiler symbol so it compiles with CUDA, and two (release and debug) which instead directs it to CPU code.
This is a short version of main.cpp:
#ifdef CUDA
#include "CUDACode.cu"
#else
#include "CPUCode.h"
#endif
int main() {
functionDefinedinBothHeaders(params);
}
but for some reason NVCC runs and compiles it fine but then the C++ compiler trys to compile it and that causes many errors that I've managed to circumvent using #ifdef __NVCC__
statements but now I have an issue where main.cpp has to use something from a header so I put is outside the #ifdef __NVCC__
statements and now I get linker error as they are defined twice as NVCC compiles it and the C++ compile does as well
error LNK2005: "class boost::random::mersenne_twister_engine<unsigned int,32,351,175,19,3433795303,11,4294967295,7,834054912,15,4293197824,17,1812433253> generator" (?generator@@3V?$mersenne_twister_engine@I$0CA@$0BFP@$0KP@$0BD@$0MMKLIOOH@$0L@$0PPPPPPPP@$06$0DBLGKLAA@$0P@$0PPOFAAAA@$0BB@$0GMAHIJGF@@random@boost@@A) already defined in CUDAStateCalc.cu.obj
the .cu files are set to CUDA C/C++ code. How do I stop it from doing that? and is there a better method than what I'm doing?
Upvotes: 0
Views: 696
Reputation: 26
Robert Crovella answered my question in the comments, what I needed to do was have a header function that was included in main.cpp
and CUDACode.cu
and contained the function prototype for functionDefinedinBothHeaders
but CUDACode.cu
defined it
Upvotes: 1