Visual Studio - CUDA 프로젝트 빌드 시 오류 C1189, expression must have a constant value
NVidia로부터 CUDA SDK를 설치 후 Visual Studio 2017에서 빌드하면 다음과 같은 오류가 발생합니다.
C1189 #error: -- unsupported Microsoft Visual Studio version! Only the versions 2012, 2013, 2015 and 2017 are supported!
위치는 "\include\crt\host_config.h"인데, _MSC_VER으로 인한 전처리 오류 메시지입니다.
#if defined(_WIN32)
#if _MSC_VER < 1600 || _MSC_VER > 1911
#error -- unsupported Microsoft Visual Studio version! Only the versions 2012, 2013, 2015 and 2017 are supported!
#elif _MSC_VER == 1600 /* _MSC_VERION == 1600 */
#pragma message("support for Microsoft Visual Studio 2010 has been deprecated!")
#endif /* _MSC_VER < 1600 || _MSC_VER > 1800 || _MSC_VERSION == 1600 */
#endif /* _WIN32 */
해결 방법은,
CUDA 9 Unsupported Visual Studio Version Error
; https://devtalk.nvidia.com/default/topic/1022648/cuda-setup-and-installation/cuda-9-unsupported-visual-studio-version-error/
단순히, 다음과 같이 헤더 파일의 내용을 변경해 주면 됩니다. (2018-03-20 현재, 최신 버전의 Visual Studio 2017에 있는 _MSC_VERSION이 1912입니다.)
#if _MSC_VER < 1600 || _MSC_VER > 1913
이렇게 변경했어도 다시 빌드하면 또다시 오류가 발생합니다.
expression must have a constant value
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.13.26128\include\type_traits
소스 코드 위치는 템플릿인데,
// STRUCT TEMPLATE is_object
template<class _Ty>
struct is_object
: bool_constant<!is_function_v<_Ty>
&& !is_reference_v<_Ty>
&& !is_void_v<_Ty>>
{ // determine whether _Ty is an object type
};
아직 CUDA 컴파일러가 C++ 최신 구문에 대한 지원을 하지 않아서 그런 것 같습니다.
The never-praised-enough StackOverflow website provides an answer: install MSVC 2015 toolset
; https://stackoverflow.com/questions/47645436/cuda-9-unsupported-error-with-vs-2017
따라서 Visual C++ 프로젝트의 "Platform Toolset" 설정을 "Visual Studio 2015 (v140)"으로 내려 컴파일하면 됩니다.
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]