我甚至无法编译CUDA 8和Visual Studio 2015 update 3的最简单代码。
CUDASample.cuh
class CUDASample {
public:
CUDASample();
~CUDASample();
};
CUDASample.cu
#include "CUDASample.cuh"
CUDASample::CUDASample() {
}
CUDASample::~CUDASample(){
}
我收到像
这样的编译错误1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(63): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(64): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(76): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(98): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(118): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(125): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(126): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(137): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(144): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(161): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(170): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(171): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(180): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(188): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(189): error : unknown attribute "guard"
我很确定这是一个CUDA问题,因为如果我将源文件扩展名更改为" cpp"和标题扩展名为" h"一切正常。我该如何解决这个问题?
编辑:
属性中显示的命令行 - >链接器 - >命令行是
/OUT:"C:\Users\David\Desktop\sample\build\bin\Release\cudasample.dll" /MANIFEST /NXCOMPAT /PDB:"C:/Users/David/Desktop/sample/build/bin/Release/cudasample.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cudart_static.lib" /IMPLIB:"C:/Users/David/Desktop/sample/build/lib/Release/cudasample.lib" /DLL /MACHINE:X64 /INCREMENTAL:NO /PGD:"C:\Users\David\Desktop\sample\build\bin\Release\cudasample.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"cudasample.dir\Release\cudasample.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1
编辑:
正如Robert所说,由于我能够成功编译cuda样本,问题可能与cmake配置有关。下面是我在Visual Studio 2013 + CUDA 7.5上编译时使用的CMakeLists。
project(cudasample)
set(PROJECT_SRCS
${PROJECT_SOURCE_DIR}/src/CUDASample.cu
)
set(PROJECT_INCS
${PROJECT_SOURCE_DIR}/include/CUDASample.cuh
)
include_directories(${PROJECT_SOURCE_DIR}/include)
find_package( CUDA REQUIRED )
list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_52,code=sm_52;")
list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_50,code=sm_50;")
list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_35,code=sm_35;")
list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_30,code=sm_30;")
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
list(APPEND CUDA_NVCC_FLAGS "-std=c++11;")
endif()
cuda_add_library(${PROJECT_NAME} SHARED ${PROJECT_SRCS} ${PROJECT_INCS})
可能出现什么问题?
答案 0 :(得分:1)
我至少设法让它发挥作用。根本原因是我脑海中的sdl编译器标志CMakeLists.txt
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /sdl")
所以,如果我在项目CMakeLists.txt
中添加这一行string(REGEX REPLACE "/sdl" "/sdl-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
它将成功编译。
然而,我仍然不清楚为什么sdl编译器标志会导致NVCC在CUDA 8和Visual Studio 2015 Update 3的组合中失败。希望有人能想出更好的答案。