當我編譯包含設計C++ 11,在Windows7x64(MSVS2012 + Nsight 2.0 + CUDA5.5),那麼我不明白的錯誤,一切編譯和下面的代碼工作得很好:我可以在Windows7x64(MSVC)和Linux64(GCC4.8.2)的.cu-files(CUDA5.5)中使用C++ 11嗎?
#include <thrust/device_vector.h>
int main() {
thrust::device_vector<int> dv(10);
auto iter = dv.begin();
return 0;
}
但是,當我嘗試編譯它下LINUX64(Debian的7 Wheezey + Nsight Eclipse的從CUDA5.5),我得到的錯誤:
../src/CudaCpp11.cu(5): error: explicit type is missing ("int" assumed)
../src/CudaCpp11.cu(5): error: no suitable conversion function from
"thrust::detail::normal_iterator>" to "int" exists
2 errors detected in the compilation of "/tmp/tmpxft_00001520_00000000-6_CudaCpp11.cpp1.ii". make: * [src/CudaCpp11.o] Error 2
當我加入一行:-stdC++ 11
在Properties-> Build中 - >設置 - >工具設置 - >構建滑臺>預處理選項(-Xcompiler)
我得到更多的錯誤:
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h(432): error: identifier "nullptr" is undefined
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h(432): error: expected a ";"
...
/usr/include/c++/4.8/bits/cpp_type_traits.h(314): error: namespace "std::__gnu_cxx" has no member
"__normal_iterator"
/usr/include/c++/4.8/bits/cpp_type_traits.h(314): error: expected a ">"
nvcc error : 'cudafe' died due to signal 11 (Invalid memory reference) make: * [src/CudaCpp11.o] Error 11
只有當我在Linux-GCC中使用thrust::device_vector<int>::iterator iter = dv.begin();
,那麼我不會收到錯誤。但在Windows MSVS2012中,所有的C++ 11功能都能正常工作!
我可以在Windows7x64(MSVC)和Linux64(GCC4.8.2)的.cu文件(CUDA5.5)中使用C++ 11嗎?
gcc 4.8.x不是linux下的[官方支持的編譯器](http://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#linux-5-5)。 –
@Robert Crovella GCC 4.7.2具有相同的效果 - 無法在nvcc + gcc中編譯C++ 11。或者,我怎麼能這樣做呢,還是我可以在nvcc + icc(Intel編譯器)中使用C++ 11? – Alex
從我的頭頂開始:最後我可以參加關於GPU編程的講座。只需1.5小時。從那裏我記得我們在幻燈片上看到的所有代碼都是基於C99的GPU的特殊語言。不知道它是否是CUDA,我不記得它。但是,如果是這樣,這意味着該語言甚至不是C或C++,它只是基於C99的。也許新功能將從C或C++的新標準中獲得,可能不會。你將不得不跟蹤特定語言的發展。但如果是別的東西,請忽略此評論。我會稍後嘗試在這個主題上找到更多。 – Palec