Search code examples
c++c++11c++14nvcc

C++11 function iota() not supported by nvcc?


I tried to compile this code:-

#include <vector>

using namespace std;

int main() {
    vector<int> v(5);
    iota(v.begin(), v.end(), 0);
}

And I compiled it with this command:-

D:\workspace\test>nvcc main.cpp --std=c++11

(Because without specifying the std I was getting the "identifier iota() not found" error)

And I get this error:-

nvcc warning : The -std=c++11 flag is not supported with the configured host compiler. Flag will be ignored.
main.cpp
main.cpp(7): error C3861: 'iota': identifier not found

How do I specify the C++ standard I want nvcc to use?

Also, compiling host code separately with g++ and device code with nvcc and then linking the objects with nvcc doesn't work. I get this.


Solution

  • There is no need. By default the command line tool nvcc uses Microsoft's cl.exe. And if your cl.exe is updated, the std option is not available. cl.exe automatically supports all the latest C++ standard's features.

    However, in cl.exe some of the functions like iota() aren't defined in the std namespace. Instead, iota() is defined in the numeric.h header file. So to run that code you would need to include the said header file. The final code should look like this:-

    #include <vector>
    #include <numeric.h>
    
    using namespace std;
    
    int main() {
        vector<int> v(5);
        iota(v.begin(), v.end(), 0);
    }
    

    The code can be compiled by the command:-

    nvcc main.cpp