Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CUDA syntax error '<'

in my test.cu file (cu file item type is CUDA C/C++)

__global__ void foo()
{
}

void CudaMain()
{

  foo<<<1,1>>>();
}

and in my test.cpp file

#include "mycuda.cu"

int main()
{

CudaMain();
return 0;

}

and compilator send me error "error c2059 syntax error ' <' " in test.cu file

like image 492
Alatriste Avatar asked Dec 11 '12 18:12

Alatriste


1 Answers

Inclusion of CUDA source files in a C++ file doesn't work because this simply makes the CUDA source part of the C++ program code and regular C++ compilers do not understand CUDA syntax extensions. If you still want to keep your CUDA code separate from the non-CUDA C++ code, then you might want to look into separate compilation. CUDA source code can be compiled to regular object files, that can then be linked with other object files to produce an executable.

Modify the C++ code to read:

extern void CudaMain(void);

int main()
{
    CudaMain();
    return 0;
}

Compile the CUDA file with nvcc, the C++ code with your C++ compiler and then link the resulting object files with nvcc (you may also need to specify the standard C++ library in the link command):

$ nvcc -c -o test_cuda.o test.cu
$ g++ -c -o test_cpp.o test.cpp
$ nvcc -o test.exe test_cuda.o test_cpp.o -lstdc++

Edit: your question is about VS2010. May be you have to create custom build steps there.

like image 107
Hristo Iliev Avatar answered Oct 05 '22 20:10

Hristo Iliev