Using TCC compiler with Sublime text 3 gives Error - c

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.

Related

Sublime Text 3, GCC build system issue

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

Sublime Text 3 compile and run (in terminal) C on OS X with passed arguments

I'm trying to compile a C program in Sublime Text 3 then run it in the terminal (which opens up through Sublime Text) on OS X Yosemite. My build system is:
{
"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}'"]
}
]
}
When I build, for example, test.c, it compiles fine. When I run the program I get this: bash: line 1: 916 Segmentation fault: 11. I'm sure this is because my program needs arguments passed to it.
So I have two questions:
How can I change the build system so that when I run it, it opens up the terminal and runs in there?
How do I pass arguments to the program before it runs? For example, on Linux I would type ./test hello 20932aa and it will run fine. How can I achieve the same on Sublime Text 3 (OS X Yosemite).
This is all you need in your build system to compile and run C code in ST3. Just replace arg1 arg2 arg3 with your arguments and save your build system before you use Tools -> Build on your C program like usual.
The && operator allows you to execute another "shell_cmd" (shell command) after the operator.
{
"shell_cmd": "make ${file_base_name} && ./${file_base_name} arg1 arg2 arg3"
}
Alternatively, here is a build system with all the bells and whistles.
{
"shell_cmd" : "gcc $file_name -o ${file_base_name}",
"working_dir" : "$file_path",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"variants":
[
{
"name": "Run",
"shell_cmd": "gcc $file_name -o ${file_base_name} && ${file_path}/${file_base_name} arg1 arg2 arg3"
}
]
}
If you want your program to open in a new terminal window, use this build system. You won't be able to pass arguments to it though.
{
"shell_cmd": "make ${file_base_name} && open -a Terminal.app ${file_path}/${file_base_name}",
}

gcc not creating output file

GCC only sometimes creates output files, and I have no idea why. I have been compiling my files in Sublime Text with this build system:
{
"cmd": ["gcc", "$file_name", "-o", "${file_base_name}", "-Wall"],
"selector" : "source.c",
"shell" : false,
"working_dir" : "$file_path"
}
GCC runs and gives me any output necessary for debugging, but once I fix the code and there are no errors, no output file is created. I have also tried running gcc input.c -o output.exe in the command line. This was all working just a few hours ago, but has seemingly randomly stopped without me changing anything.

sublime text 2 can't run my c program?

i am using Windows 7 and I have added
{
"cmd" : ["gcc", "$file_name", "-o", "${file_base_name}.exe", "-lm", "-Wall"],
"selector" : "source.c",
"shell":true,
"working_dir" : "$file_path"
}
to my c.sublime-build and although it can build my program, the run option disappears. So I can not see the output of my simple hello world program.
You need to add a variant for the Run option that will execute the program. Here's what my g++.sublime-build looks like
{
"shell_cmd": "g++ \"${file}\" -O3 -std=c++11 -pedantic -Wall -Wextra -Wconversion -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}\" -O3 -std=c++11 -pedantic -Wall -Wextra -Wconversion -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
}
]
}
My Run option builds and then runs the program, get rid of the first half of the command if you only want it to run the executable.

How to Run and Compile .c on Sublime Text 2 [MAC OS X]

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

Resources