When building a working ".c" code file I experience an error building with the menu icons to build(build system GCC)
When I navigate: tools -> build (with GCC selected as build system)
'main.exe' is not recognized as an internal or external command,
operable program or batch file.
[Finished in 0.1s with exit code 1]
[cmd: ['main.exe']]
[dir: C:\Users\erik\Documents\Carleton University\Sysc 2006\Lab 11\Recursion\Recursion]
[path: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin;C:\Perl64\site\bin;C:\Perl64\bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\MinGW\bin;C:\MinGW\mingw32\bin;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\PharosSystems\Core;C:\Python35-32;C:\Python35-32\Lib\site-packages\;C:\Python35-32\Scripts\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Users\erik\AppData\Local\bin\NASM;C:\Program Files\Git\cmd;C:\Users\erik\AppData\Local\Microsoft\WindowsApps;C:\altera\13.0sp1\modelsim_ase\win32aloem;C:\Users\erik\AppData\Local\GitHubDesktop\bin;]
But if i navigate: tools -> command palette -> build with:GCC
[Finished in 0.5s]
Following this beloved visual above I would then navigate: tools -> build (with GCC selected as build system), OR tools -> command palette -> build with:GCC -RUN
***Expected working output***
This is my GCC.sublime-build file, I suspect this is the file that is causing issues.
// Put this file here:
// "C:\Users\[User Name]\AppData\Roaming\Sublime Text 3\Packages\User"
// Use "Ctrl+B" to Build and "Crtl+Shift+B" to Run the project.
// OR use "Tools -> Build System -> New Build System..." and put the code there.
{
"cmd" : ["gcc", "$file_name", "-o", "${file_base_name}.exe"],
// Doesn't work, sublime text 3, Windows 8.1
// "cmd" : ["gcc $file_name -o ${file_base_name}"],
"selector" : "source.c",
"shell": true,
"working_dir" : "$file_path",
// You could add path to your gcc compiler this and don't add path to your "PATH environment variable"
// "path" : "C:\\MinGW\\bin"
"variants" : [
{ "name": "Run",
"cmd" : ["${file_base_name}.exe"]
}
]
}
Although the issue may be here, I am very concerned it may also be elsewhere as I have been struggling with implementing libraries.
A second side question would be why is my "Path:" variable so long, is it unnecessarily long? many of those would not be needed in sublime correct?
This will allow you to compile and run c++ programs in sublime as well as command prompt also
{
"shell_cmd": "g++ -Wall -std=c++11 \"${file}\" -o \"${file_path}/${file_base_name}.exe\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[ // to run in the sublime text console
{
"name": "Run",
"shell_cmd":"\"${file_path}/${file_base_name}\""
},
// to run in the Windows command line
{
"name": "Run in cmd",
"shell_cmd": "start cmd /k $file_base_name "
}
]}
Related
I like Sublime a lot and wish to execute my program directly from the editor. I've done it with gcc, but now want to use tcc.
I can't find a build system for tcc so I took a C++ build system. There is a problem that it can't find the file I want to execute. Here's my build system:
{
"shell_cmd": "tcc \"${file}\" -o \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c",
"variants":
[
{
"name": "Run",
"shell_cmd": "tcc \"${file}\" -run \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
}
]
}
I changed g++ to tcc and -o to -run but it giving a file not found error.
tcc: error: file 'C:\Users\Paras Ghai\Documents\C Projects/Binary_Search' not found
Here after Documents\C Projects it is showing / in place of \. Is that the problem? How do I fix it?
So I did some changes and finally created a simple build-system for my tcc compiler and here it is->
{
"windows":
{
"cmd": ["tcc","-std=c99" ,"-run", "$file_name"]
},
"selector" : "source.cpp",
"shell": true,
"working_dir" : "$file_path",
}
I hope that it works for other people too.
Im trying to compile C code in Sublime text editor.
In sublime I went into Tools->Build Systems->New Build System. And pasted in.
}
"cmd" : ["gcc", "$file_name", "-o", "${file_base_name}.exe", "&&", "${file_base_name}.exe"],
"selector" : "source.c",
"shell" : true,
"working_dir" : "$file_path"
}
My environmental variable path is following:
C:\Program Files (x86)\Java\jdk1.8.0_77\bin;C:\MinGW\bin
When I try to compile my C code, the output is:
[Finished in 0.0s with exit code 1]
[cmd: ['gcc', 'test.c', '-o', 'test.exe', '&&', 'test.exe']]
[dir: C:\Users\Felix\Desktop\prog\C]
[path: C:\Program Files (x86)\Java\jdk1.8.0_77\bin]
Why is my path wrong? Why did I get an exit code of 1? How should I do?
I'm using Sublime Text 3 for C programming. I want to compile and run my programs in the gnome terminal using a keybinding or something like that instead of the ST3 console (like CodeBlocks does). How can I do it?
Click Tools->Build System->New build system to add a new build system, copy following code:
{
"cmd" : ["gnome-terminal -x bash -c \"gcc $file_name -o ${file_base_name} -lm -Wall; ./${file_base_name}; exec bash\""],
"selector" : "source.c",
"shell":true,
"working_dir" : "$file_path"
}
Save this file.
Then click Tools->Build System to choose the newly stored build system. Every time you press "Ctrl+B", the keybinding of Tools->build, it will run gnome-terminal and compile&run your program automatically.
I am trying to run c programs in sublime 2, windows machine, I have installed mingw, updated the path variable, and copied the following code in the sublime new build system
{
"cmd": ["gcc -o $file_base_name $file && ./$file_base_name"],
"path": "C:/Program Files (x86)/CodeBlocks/MinGW/bin",
"shell": true
}
Then i wrote a simple C program
#include<stdio.h>
int main()
{
printf("ihdfoihsdifhoisdhf");
return 0;
}
On pressing CTRL+SHIFT+b and CTRL+b , i am getting the following error
'.' is not recognized as an internal or external command,
operable program or batch file.
[Finished in 0.4s with exit code 1]
The problem is most likely here:
"cmd": ["gcc -o $file_base_name $file && ./$file_base_name"],
The dot-slash is current-directory notation for *nix systems, but you're on a Windows system, so try changing that to
"cmd": ["gcc -o $file_base_name $file && $file_base_name"],
Likewise, you will want to change the forward-slashes / in your path to backslashes \.
I am learning C at college now, and teachers told me to use codeblocks as an IDE, but in my opinion codeblocks is a bit ugly and that's why I've chosen Sublime Text 2, the BEST IDE/Text Editor out there.
At the moment I write my code via sublime, save it and then compile it via mac os terminal (gcc) and than run it on the terminal as well...
What I want to know, if it is even possible, is how to do it right from sublime, using its console or a plugin (or something), in other words I want to know if it is possible to compile my .c and run it with only e few clicks right on sublime... (for now I am just building console applications)
I've read some posts here about this topic but none of those helped me to solve this.
A basic C build file could look like this:
{
"cmd" : ["/path/to/gcc", "$file_name", "-o", "${file_base_name}", "-lgsl", "-lgslcblas", "-lm" , "-Wall"],
"selector" : "source.c",
"shell":false,
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "/path/to/gcc '${file}' -Wall -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
To just compile you press command + b.
To compile then run you would press command + shift +b
The only thing you need to do is put the path to your gcc and inlcude the libraries you use (I left some GSL stuff for this example). The $_variables are sublime build system variables and should not be changed. For more info on those variables, look here.
You can put the actual build system file here:
~/Library/Application Support/Sublime Text 2/Packages/User/C.sublime-build
I used the following as a .sublime-build to compile and run C. Basically an edit of the code used for C++. Worked for me.
{
"cmd": ["gcc", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "gcc '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
If you are using a makefile you could use something like this:
{
"cmd" : ["/usr/bin/make"],
"selector" : "source.c",
"shell":false,
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "/usr/bin/make && '${file_path}/${file_base_name}'"]
}
]
}