If I compile boost using code in a .cu, then the make fails with strange errors.
If I simply rename the .cu file to .cpp, the boost code compiles, but the cuda code fails, due to unknown references to cuda-specific things like threadIdx.x.
The error is that shows up when including thread.hpp is:
$ nvcc -Xcompiler -fPIC -shared -o libCudaCallC.so main.cu -I/opt/cuda/sdk/C/common/inc/
/usr/include/boost/lexical_cast.hpp(328): error: expected an expression
/usr/include/boost/lexical_cast.hpp(328): error: expected a “;”
2 errors detected in the compilation of “/tmp/tmpxft_00000823_00000000-4_regression.cpp1.ii”.
There appears to be nothing wrong with the lexical_cast file as both the file itself, and thread.hpp, can be correctly included in other projects.
I would suggest separating your host and device code.
Place your host code in a cpp file and your device code in a cu file. You can then compile your host code with gcc and the device code with nvcc and link them. I’d imagine gcc would handle the boost includes without any problems.
This is always an option but I still consider this bad behaviour. According to the documentation of build pipeline, host code should be automatically handed over to the base compiler. If nvcc trips over this, it might mean it tries to compile more than it should?
Oh, sorry. I forgot the -lcudart in the finally linking step. That should solve your undefined symbol: __cudaRegisterFatBinary problem. You may also need -L /dir/to/cuda
Any updates on this problem? I am encountering it with the CUDA 3.0 Beta. It would be really nice if nvcc could pass boost to the host compiler correctly…