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.
Related
I have been stuck on this bug for a few hours now.
I wrote some code in C that uses functions and structs from another C file that I wrote. when I run the code manually (with the makefile I wrote) it runs.
the makefile:
exec: ../LineParser.c main_c_file.c
gcc -g -m32 -Wall -c ../LineParser.c -o LineParser.o
gcc -g -m32 -Wall -c main_c_file.c -o main_c_file.o
gcc -g -m32 -Wall LineParser.o main_c_file.o -o main_c_file
rm LineParser.o main_c_file.o
but when I am trying to debug it I get the error:
/dir1/dir2/task2/main_c_file.c:123: undefined reference to imported_function'
collect2: error: ld returned 1 exit status
Build finished with error(s).
* The terminal process failed to launch (exit code: -1).
I tried
adding -g to the make file.
to first compile the code
and then add its full path to the program tag in the debug configuration file
{
linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "by-gdb",
"request": "launch",
"name": "Launch(gdb)",
"program": "/dir1/dir2/main_c_file",
"cwd": "${workspaceRoot}"
}
]
}
by the way I am runing this code in Linux
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.
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 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.
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}'"]
}
]
}