Sublime Forum

Issues with building any C++ on Sublime Text 3

#1

So I’m trying to build a C++ program on Sublime Text 3 but I keep getting a variety of issues.

I have HelloWorld.cpp below, in directory C:\Users\kevin\Desktop\C++:

#include <iostream>
#include <string>

int main(){
    std::cout <<  "Hello World!" << std::endl;
    std::cout <<  "Hello World!" << std::endl;
    std::cout <<  "Hello World!" << std::endl;
    std::cout <<  "Hello World!" << std::endl;
    return 0;
}   

First try: build and run with built-in C++ Single File generates this error:

Access is denied.
[Finished in 2.6s with exit code 1]

Second try: building with build file CPP.sublime-build:

{
 "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}'"]
   }
 ]
}

[WinError 2] The system cannot find the file specified
[cmd: ['bash', '-c', "g++ -std=c++	 -Wall 'C:\\Users\\kevin\\Desktop\\C++\\HelloWorld.cpp' -o 'C:\\Users\\kevin\\Desktop\\C++/HelloWorld' && 'C:\\Users\\kevin\\Desktop\\C++/HelloWorld'"]]
[dir: C:\Users\kevin\Desktop\C++]
[path: C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Bitvise SSH Client;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Java\jdk1.8.0_121\bin;C:\Program Files (x86)\Skype\Phone\;C:\MinGW\bin;C:\Users\kevin\AppData\Local\Microsoft\WindowsApps;]
[Finished]

I’ve installed MinGW, and have edited my environmental PATH variable to include C:\MinGW\bin.

Additional details: Running Windows 10, x64 based PC.

Any ideas?

0 Likes

#2

Based on the comments on your SO question, you get the Access is Denied error even in the terminal when you run the compiled program, correct?

In that case I would guess that the problem is less Sublime and more something weird going on with the compiled executable itself. It’s been years since I’ve done anything of substance in C++ (although I use C in my day job) but nothing seems particularly standout-ish as a potential problem there.

Possibly there is some weird interaction with g++ and how it’s generating a console program or something. That error sounds like the issue is that you don’t have access to stdout for displaying the messages, though I don’t know that I’ve ever seen that happen before.

In regards to your custom build, can you say why you’re trying to use bash to run the command instead of just executing the command directly?

The error you’re getting there is generally indicative of Windows not being able to find bash in order to run it. Assuming that bash isn’t in the MinGW directory you mentioned, it may help to add the bash location to the path as well.

0 Likes

#3

I faced the same issue, In my case, I downloaded Sublime text 3 for 32 and 64 bit both but I installed the 64bit version. But after deleting the 32-bit version, the problem resolved.this is what I saw while running some code (The access denied issue).


After deleting the 32bit version I got this.
I hope this helps.:grinning:

0 Likes

#4

After deleting the 32-bit version i got this

0 Likes