I know nvcc only compiles .cu
files, and pass .c
or .cpp
to designated compilers like gcc, g++, clang, clang++, etc...
Here's my problem.
Thrust headers in .h
file in Windows which uses cl.exe complied just fine.
But the same codes in Linux with g++ or clang++ didn't compile complaining no such headers like thrust/device_vector.h
and so on.
So my theory is: Windows nvcc uses cl.exe to compile both .cpp
and .cu
, which means cl.exe
can compile Thrust or CUDA related codes.
Linux on the other hand, Linux nvcc uses CUDA compiler to compile .cu
and g++ or clang++ to compile .cpp
files, which means .h
or .cpp
files with Thrust or CUDA related code cannot be compiled with.
It that right?
If not, why can Windows nvcc compile .h
with Thrust, but Linux nvcc cannot?
The compilation process is similar for Linux and Windows. The NVCC compiler driver separates host and device code, then invokes your platform's C++ compiler. For more information, refer to this section of the NVCC documentation.
Thrust headers are not included in the search path by default when using g++
or clang++
, however you can provide it explicitly using the -I
flag. Example below with a simple C++ file including CUDA and Thrust headers:
$ cat test.cc
#include <cuda_runtime.h>
#include <thrust/device_vector.h>
int main(void)
{
}
$ g++ -I/usr/local/cuda/include/ test.cc -o test
$ ./test