Sublime Forum

C/cpp compiler only shows build time and "finished"

#1

I successfully created my own Python 3.8 compiler in sublime, which works like a charm. Now i installed MinGW64 on my windows 10 machine. Which is working, i can use “gcc --version” and “g++ --version” in cmd (so PATH is working).

I saw this post about setting up c/c++ compiler in sublime: https://www.thecrazyprogrammer.com/2017/04/how-to-run-c-and-c-program-in-sublime-text.html

{
"shell_cmd": "g++ \"${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",
		"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
	}
]
}
#include <iostream>

int main() {
    std::cout << "Hello World!";
    return 0;
}
{
"shell_cmd" : "gcc $file_name -o ${file_base_name}",
"working_dir" : "$file_path",
 
"variants":
[
	{
		"name": "Run",
		"shell_cmd": "gcc $file_name -o ${file_base_name} && ${file_path}/${file_base_name}"
	}
]
}
#include<stdio.h>

int main() {
	printf("Hello World\n");
	return 0;
}

But both compilers only says:

[Finished in 1.1s]

with no “Hello World” output. I used the correct (basically my own) build systems.

0 Likes

#2

Are you sure you selected the right build system? Use ctrl+shift+b to select the desired build system.

1 Like

#4

Oh well, yes. My CPP.sublime-build has this content

{
"shell_cmd": "g++ \"${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",
		"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
	}
]
}

And i just run the build and ignored the variant Run. This one works.

But this one only works for CPP, not for the C problem:

{
"shell_cmd" : "gcc $file_name -o ${file_base_name}",
"working_dir" : "$file_path",
 
"variants":
[
	{
		"name": "Run",
		"shell_cmd": "gcc $file_name -o ${file_base_name} && ${file_path}/${file_base_name}"
	}
]
}

Runs into

The system cannot execute the specified program
[Finished in 1.8s with exit code 1]
[shell_cmd: gcc test.c -o test && C:\Users\user\Desktop/test]
[dir: C:\Users\user\Desktop]
[path: C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\PuTTY;C:\Users\user\AppData\Local\Programs\Python\Python38\Scripts;C:\Users\user\AppData\Local\Programs\Python\Python38;C:\Users\user\AppData\Local\Microsoft\WindowsApps;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\Nsight Compute 2020.1.0;C:\MinGW\bin;C:\Users\user\AppData\Local\Programs\Python\Python38\Scripts;C:\Users\user\AppData\Local\Programs\Python\Python38;C:\Users\user\AppData\Local\Microsoft\WindowsApps;C:\Python27;C:\Python27\Scripts;C:\MinGW\bin;]

The path looks weird: [shell_cmd: gcc test.c -o test && C:\Users\user\Desktop/test
Backslash and slash…?

0 Likes

#5

Your C build system should be identical to your C++ build system except for g++ being replaced by gcc. Your output file (-o test) is different to the file it’s trying to run (C:\Users\user\Desktop/test) in the C build system, hence why you’re getting that error message.

0 Likes

#6

I changed my C.sublime-build now to this

{
"shell_cmd": "gcc \"${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",
		"shell_cmd": "gcc \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
	}
]
}

so its like CPP.sublime-build but i replaced g++ with gcc. Still:

[Finished in 1.6s with exit code 1]
[shell_cmd: gcc “C:\Users\user\Desktop\test.c” -o “C:\Users\user\Desktop/test” && “C:\Users\user\Desktop/test”]
[dir: C:\Users\user\Desktop]

0 Likes