0x6K5
0x6K5

Reputation: 57

Detect if c++11 is enabled in NVCC

I would like to detect whether a .cu file is compiled with C++11 support enabled. At the moment i have the following:

#if CUDART_VERSION < 7050
  #define C11SUPPORTED 0
#else
  #define C11SUPPORTED 1
#endif

However this is not working because even though C++11 is supported, it is not enabled unless -std=c++11 switch is passed. Is there perhaps something else defined when -std=c++11 is passed?

Update

nvcc --compiler-options -dM -E -x cu - < /dev/null | grep "__cplus"

returns

#define __cplusplus 201402L

I am using NVCC version V9.1.85. Will checking __cplusplus work, even for older NVCC versions?

Upvotes: 1

Views: 731

Answers (1)

Michael Karcher
Michael Karcher

Reputation: 4111

If nvcc is standard conforming, you should be able to check the value of __cplusplus like this

#if __cplusplus >= 201103
#define C11SUPPORTED 1
#else
#define C11SUPPORTED 0
#endif

Checking the value of __cplusplus should work with any C++ compiler since at least C++98.

Upvotes: 3

Related Questions