Sublime Forum

The Bash for successful build and run C++ 11 & C++ 14

#1

Hello!
I need help, to understand how to deal with the bash in my path to build and run C++ 11 and C++ 14

C++ Build System, build and run perfectly fine!!!

C++11 Build, but not Run. (It let me run .exe file manually with PowerShell or CMD)

my C++11.sublime-build file:
{

 "cmd": ["g++", "-std=c++11", "${file}", "-o", "${file_path}/${file_base_name}"],

 "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",

 "working_dir": "${file_path}",

 "selector": "source.c, source.c++",

 "variants":

 [
   {
     "name": "Run",
     "cmd":["bash", "-c", "g++ '${file}' -std=c++11 -stdlib=libc++ -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
   }

 ]
}

C++14 Doesn’t Build & Run.

my C++14.sublime-build file:
{

 "cmd":["bash", "-c", "g++ -std=c++14 -Wall '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"],

 "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",

 "working_dir": "${file_path}",

 "selector": "source.c, source.c++",

 "variants":

 [
   {
     "name": "Run",

     "cmd":["bash", "-c", "g++ -std=c++14 '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
   }
 ]
}

The error I got to the console:

[WinError 2] The system cannot find the file specified[cmd: ['bash', '-c', "g++ -std=c++0x 'C:\Users\FTP-RSky\Desktop\RSky\rect\test_g++11.cpp' -o 'C:\Users\FTP-RSky\Desktop\RSky\rect/test_g++11' && xterm -e bash -c 'C:\Users\FTP-RSky\Desktop\RSky\rect/test_g++11; read'"]] [dir: C:\Users\FTP-RSky\Desktop\RSky\rect] [path: C:\Program Files\Processing-3.2.1;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files\Java\jdk1.8.0_73\bin\lib;C:\Program Files\Java\jdk1.8.0_73\bin] [Finished]

Using POSIX paths, will it really helps to solve this problem or is some other way to setup Build System properly for modern C++ 14 standard?
Thanks!

0 Likes

#2

I asked you this on stack overflow and I’ll ask you again; if you know that running g++ works as expected, but running bash -c g++ does not work, why don’t you just try modifying the command line on the version that works to specify version 14? Does that work? Can you upgrade your MinGW installation to a version that handles that version of the C++ standard if the reason that it doesn’t work is because MinGW doesn’t support it?

Working under the assumption that you’re using Windows 10 and you’re trying to use Windows Subsystem for Linux to run bash to get it to run the Linux g++ compiler you installed, the error message “The system cannot find the file specified” is telling you that “windows cannot find the file specified”.

I would try either adding the path that bash is installed in to your windows path or specifying the full absolute path to bash in your build system and see if that works.

0 Likes

#3

Finally it’s works! These new lines fixed everything:

    {
 "shell_cmd": "g++ -std=c++14 \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\"",
     "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
     "working_dir": "${file_path}",
     "selector": "source.c, source.c++",
     "variants":
     [
     	
       {
         "name": "Run",
        "shell_cmd": "g++ -std=c++14 \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
       }
     ]
    }

Thank you for your response, it helps a lot!

1 Like

#4

I am having this error, can anybody please help me out

!
after building again I got this message: [shell_cmd: g++ -std=c++14 “C:\Users\LENOVO\Desktop\cpp\source.cpp” -o “C:\Users\LENOVO\Desktop\cpp/source” && “C:\Users\LENOVO\Desktop\cpp/source”]
[dir: C:\Users\LENOVO\Desktop\cpp]
[path: C:\Program Files (x86)\Lenovo\FusionEngine;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\WINDOWS\System32\OpenSSH;C:\MinGW\bin;C:\Users\LENOVO\AppData\Local\Microsoft\WindowsApps;C:\Users\LENOVO\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin;]

0 Likes