最近在做的项目中既用到了Cuda,同时又用到了C++11的一些新的特性,在用gcc编译的时候会出现错误。
错误提示为:
/usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++config.h(159): error: identifier "nullptr" is undefined
/usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++config.h(159): error: expected a ";"
/usr/include/c++/4.6/bits/exception_ptr.h(93): error: incomplete type is not allowed
/usr/include/c++/4.6/bits/exception_ptr.h(93): error: expected a ";"
/usr/include/c++/4.6/bits/exception_ptr.h(112): error: expected a ")"
/usr/include/c++/4.6/bits/exception_ptr.h(114): error: expected a ">"
经过查找资料后发现是由于Cuda5.5目前还不支持C++11。为了解决这个问题,我们要将cuda程序也就是以.cu结尾的文件单独编译,在编译cuda程序的时候指定编译标准为C++03,这样就不会发生上述的错误。
我的具体解决方案是:在编译cuda文件的CMakeLists.txt中用命令SET(CUDA_NVCC_FLAGS --compiler-options "-std=c++03";-arch=sm_20)指定nvcc的编译选项。
参考资料:
转载请注明出处。