Cuda5.5不支援C++11的解決方法
阿新 • • 發佈:2019-01-04
最近在做的專案中既用到了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的編譯選項。
參考資料:
轉載請註明出處。