Reputation: 91
I created a new build system in my Sublime Text 3 for C++ 14 and pasted the below code and saved it as c++ 14.
{
"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}'"]
}
]
}
But whenever I select this build (saved C++ 14
) to run my c++ program then my Sublime Text gives the following error :
[WinError 2] The system cannot find the file specified
[cmd: ['bash', '-c', "g++ -std=c++14 -Wall 'C:\\Users\\ragha\\Desktop\\All_Folders\\sublime_cpp\\_code.cpp' -o 'C:\\Users\\ragha\\Desktop\\All_Folders\\sublime_cpp/_code' && 'C:\\Users\\ragha\\Desktop\\All_Folders\\sublime_cpp/_code'"]]
[dir: C:\Users\ragha\Desktop\All_Folders\sublime_cpp]
[path: C:\Python38\Scripts\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Calibre2\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Java\jdk-14.0.1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Python38\python.exe;C:\Python38;C:\MinGW\bin;C:\Users\ragha\AppData\Local\Microsoft\WindowsApps;C:\src\flutter\bin;C:\MinGW\bin;]
[Finished]
NOTE - I HAVE ALREADY INSTALLED MinGW C++ INSTALLER. I have added C:/MinGw/bin to the path in both Global Variables as well as System Variables
. My C++ program runs well when I run it using C++ single file
build. I don't have any WSL in my system.
How to fix the problem.
Please Help!
Upvotes: 1
Views: 2436
Reputation: 102852
Here is a new build system to try:
{
"shell_cmd": "bash -c \"g++ -std=c++14 -Wall '${file}' -o '${file_path}/${file_base_name}.exe' && '${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", "'${file_path}/${file_base_name}'"]
}]
}
The "shell_cmd"
takes all of its arguments as one string, so I combined it all together with escaped double quotes as needed, and made some tweaks so that it runs, at least for me.
I also changed your Run
section to just run the already-compiled binary. In your original one you were compiling again before running. You'll notice that I used the "cmd"
function here, where the arguments are an array of comma-separated strings.
Please note that this build system still runs the binary inside Sublime's console, so you can't do some things, like request input from the user. However, if you would like to run your program in a separate command prompt in order to accept user input, for example, use this build system below:
{
"shell_cmd": "g++ -std=c++14 -Wall ${file} -o ${file_path}/${file_base_name}.exe && start cmd /k ${file_path}/${file_base_name}",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"shell": true,
"variants": [
{
"name": "Run",
"cmd": ["start", "cmd", "/k", "$file_base_name"],
"working_dir": "${file_path}",
"shell": true,
}]
}
If you just want to compile and run your program inside Sublime, this should work:
{
"shell_cmd": "g++ -std=c++14 -Wall ${file} -o ${file_path}/${file_base_name}.exe && ${file_path}/${file_base_name}",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"shell": true,
"variants": [
{
"name": "Run",
"cmd": ["$file_base_name"],
"working_dir": "${file_path}",
"shell": true,
}]
}
Upvotes: 2