Sublime Text 2 Build System - c++

I managed to get this build system doing the trick for me:
{
"working_dir": "${file_path}",
"cmd": ["g++", "${file}"],
"variants":
[
{
"name": "Run",
"shell": true,
"working_dir": "${file_path}",
"cmd": ["start", "a.exe"]
}
]
}
But I don't want the shell to close once if finishes. I want it to display a message like "Build process complete. Press any key to exit...". Is there any way to accomplish this?

Not the best solution, but I found out that adding a
while(true){}
to the end of the file makes it not close. Still waiting for a better solution tho.

Related

sublime text terminus build cancel does nothing

The title says it all, build cancel does nothing, command pallet does nothing, keybind does nothing. I have changed the keybind from prefrences with this:
{ "keys": ["ctrl+alt+c"], "command": "cancel_build" },
I have added my own Python terminus build:
{
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
"focus": true,
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
"windows": {
"cmd": ["py", "-u", "$file"],
},
"variants":
[
{
"name": "Syntax Check",
"cmd": ["python3", "-m", "py_compile", "$file"],
"windows": {
"cmd": ["py", "-m", "py_compile", "$file"],
}
}
]
}
(I am really new to sublime text and also to coding) Thanks in advance.
Edit: I am using Windows 10, in python installer I have selected the add to PATH option and changing keybind does nothing. I use this as my test file:
while True:
print("Stop it!")
There was not even a problem, the code I was running was so hard on my system that cancelling took ages. (Props to #OdatNurd for finding it)

Sublime Text 3 does not accept fortran from MinGW

I am trying to set fortran (G95) from MinGW to work in Sublime Text 3.
I looked at How do you configure MinGW with Sublime Text 3? and Could someone help me configure MinGW in SublimeText 3? (Newbie) a I found this:
{
"cmd": ["gcc", "${file}", "-o", "${file_base_name}.exe"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"shell": true,
"variants":
[
{
"name": "Run",
"cmd": ["start", "cmd", "/k", "${file_path}/${file_base_name}.exe"],
"shell": true
}
]
}
so i created the file packages/user/fortran(G95).sublime-build. There I dont know what to write in ${file_path} or ${file_base_name} variable so I tried this:
{
"cmd": ["gcc", "C:/MinGW/bin", "-o", "g95.exe"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "C:/MinGW/bin",
"selector": "source.c, source.c++",
"shell": true,
"variants":
[
{
"name": "Run",
"cmd": ["start", "cmd", "/k", "C:/MinGW/bin/g95.exe"],
"shell": true
}
]
}
but it returns:
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe:
cannot find C:/MinGW/bin: Permission denied collect2.exe: error: ld
returned 1 exit status [Finished in 0.3s].
Was I doing it right or did I mess up something doring the creation of the file.
Thank you very much for any advice and help to make this work.
PS:I already have in PATH C:/MinGW/bin and C:/MinGW/mingw32/bin. And I use Windows 10 64-bit.
Edit:
Now I did change the file back to this:
{
"cmd": ["gcc", "${file}", "-o", "${file_base_name}.exe"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"shell": true,
"variants":
[
{
"name": "Run",
"cmd": ["start", "cmd", "/k", "${file_path}/${file_base_name}.exe"],
"shell": true
}
]
}
But it says that it does not know the write function and more in my Hello world program.
C:\Users\TPN~1\AppData\Local\Temp\ccV3Loja.o:helloworld.f90:(.text+0x3b):
undefined reference to _gfortran_st_write'
C:\Users\TPN~1\AppData\Local\Temp\ccV3Loja.o:helloworld.f90:(.text+0x59):
undefined reference to_gfortran_transfer_character_write'
C:\Users\TPN~1\AppData\Local\Temp\ccV3Loja.o:helloworld.f90:(.text+0x67):
undefined reference to _gfortran_st_write_done'
C:\Users\TPN~1\AppData\Local\Temp\ccV3Loja.o:helloworld.f90:(.text+0x8a):
undefined reference to_gfortran_set_args'
C:\Users\TPN~1\AppData\Local\Temp\ccV3Loja.o:helloworld.f90:(.text+0x9e):
undefined reference to `_gfortran_set_options' collect2.exe: error: ld
returned 1 exit status [Finished in 1.0s]
You should not change ${file}, ${file_base_name} or ${working_dir}. Theses variables are parsed by ST to execute the right cmd, see the official help and the more complete unoffical help.
As you already added C:/MinGW/bin and C:/MinGW/mingw32/bin to your PATH, just revert to the original file packages/user/fortran(G95).sublime-build, with the following changes to handle fortran files then restart Sublime-text and you should be good to go.
{
"cmd": ["gfortran", "${file}", "-o", "${file_base_name}.exe"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.f, source.f90, source.f95",
"shell": true,
"variants":
[
{
"name": "Run",
"cmd": ["start", "cmd", "/k", "${file_path}/${file_base_name}.exe"],
"shell": true
}
]
}

Sublime Text 3 C++ build system

Hello I messed up a little with C++ build system in Sublime Text 3 and now I can't run any program.
Here is my build system:
{
"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",
"cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && open -a Terminal -e \"${file_path}/${file_base_name}\""
}
]
}
Thanks for help,
Nenor
The only wrong think seems to be the way you write the command. It's not stated in the new documentation, but in the old one you can read
cmd:
Array containing the command to run and its desired arguments.
So, this build system should do the trick (this is the default provided):
{
"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",
"cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
Please note that someone has previously reported having trouble with the C++.sublime-build provided by default (it's all fine on my OS X). If that's the case, consider salek's reply on this answer.

Sublime Text 2 How To Change Default Runtime Shell Command For C++?

I'm trying to run a c++ program through sublime text 2. I do not want to add bash to my PATH. I want to change the default cmd command to the following:
./${file}
I looked all around in the c++ packages folder but only found the build.
I appreciate some help!
[EDIT]
My program builds correctly, but upon runtime I get this:
[Error 2] The system cannot find the file specified
[cmd: [u'bash', u'-c', u"g++ 'C:...]
[dir: C:\Users\...]
[path: C:/.../
[Finished]
[EDIT] As per requested, my build file.
{
"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",
"cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
{
"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",
"cmd": ["${file_path}/${file_base_name}"]
}
]
}
Just drop the compilation command and retain only the executable invocation part. But remember, you have to compile before running otherwise the executable would not have got generated.

Can't build C++ program using Sublime Text 2

I think many of you are using or used to use Sublime Text 2 editor. I have strange error: C++ programs can't be built.
My C++.sublime-build:
{
"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"],
"working_dir": "${file_path}",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
I found that when the cmd array contains ANY substituted expression like ${file} or $file, build doesn't start. Otherwise it starts.
It doesn't matter from compiler. When I've tried "cmd": ["notify-osd", "$file"], it didn't work; but with "cmd": ["notify-osd", "sometexthere"] it worked.
Compiling by-hand works right.
My program:
#include <iostream>
int main() {
std::cout << "Hello World";
}
I use Ubuntu 12.04, 32bit. Version of Sublime Editor: 2.0.1.
If it isn't the place where I could ask this question, please tell me what's the right one.
Edit your C++.sublime-build file....works like a charm.
{
"cmd": ["g++", "-Wall", "-Wextra", "-pedantic", "-std=c++11", "${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",
"cmd": ["bash", "-c", "g++ -Wall -Wextra -pedantic -std=c++11 '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
I can provide a workaround solution to this problem: Use makefiles. Sublime Text 2 can run makefiles to compile c++ for you.
You would be more likely to get a better answer to this question by asking in the Sublime forums (http://www.sublimetext.com/forum/).
Even there they would probably be interested in knowing "how" it doesn't work (i.e. if nothing happens at all when pressing "Build", you might want to specify that).
It took me several hours to get C++ compiling working on Sublime Text, and I still have some slight problems (like the fact that Sublime Text can't apparently execute the program in an externe window/console).
Here's my config file:
{
"cmd": ["C:\\MinGW\\bin\\mingw32-g++.exe", "-Wall", "-time", "$file", "-o", "$file_base_name"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"working_dir": "${project_path:${folder}}",
"selector": "source.c",
"shell": true,
"encoding": "latin1"
}
(make sure to change the encoding to utf8 if the compiler doesn't work)
Also, add the MinGW's bin folder to your OS's Path variable (look up 'environment variable' in the start menu, and then look for the Path variable).