Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++ 5.4.0 - unable to use C++14 standard

I installed gcc 5.4.0 recently, on Windows using Cygwin, because I wanted to test the C++14 standard features of g++. When I tried to compile, I get the following error:

$ g++-5.4.0 -std=c++14 test.cpp
-bash: g++-5.4.0: command not found

This is the code I wrote inside test.cpp:

#include <iostream>

int main()
{
    auto lambda = [](auto x){ return x; };
    std::cout << lambda("Hello generic lambda!\n");
    return 0;
}

What could be the problem? I also tried replacing C++14 with C++11 in the command, but got the same error.

like image 731
Ebin J Avatar asked Jun 25 '16 06:06

Ebin J


1 Answers

When Cygwin installs a g++ version (in your case, 5.4.0), it will place the g++ executable in your PATH variable. But the installation name is just g++.exe, so you can call the program like this:

g++ -std=c++14 test.cpp

If you really wanted to call the compiler with g++-5.4.0, you could symlink the actual g++ executable to that name:

ln -s /usr/bin/g++.exe /usr/bin/g++-5.4.0.exe

then you will be able to call the program from the command line with either g++ or g++-5.4.0:

g++-5.4.0 -std=c++14 test.cpp
g++ -std=c++14 test.cpp
like image 55
Tyler Lewis Avatar answered Dec 16 '22 10:12

Tyler Lewis