Sublime Text 3 does not accept fortran from MinGW - fortran

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

Related

SublimeText C++ build on Windows

I'm using SublimeText-3 on Winodws 7 to do C++ programming, trying to take advantage of the build feature.
I created a C+++.sublime-build file in which I point to the compiler I would like to use, the same used by Qt installation ("path": "C:/Qt/Qt5.5.1/Tools/mingw492_32/bin").
{
"cmd": ["g++", "-o", "${file_path}/${file_base_name}.exe", "-static-libgcc", "-static-libstdc++", "*.cpp"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.cpp, source.c++",
"path": "C:/Qt/Qt5.5.1/Tools/mingw492_32/bin",
"shell": true,
"variants": [
{
"name": "Run",
"cmd": ["g++", " -std=c++1y", "-o", "${file_path}/${file_base_name}.exe", "-static-libgcc", "-static-libstdc++", "*.cpp", "&", "${file_path}/${file_base_name}.exe"]
}
]
}
But when I hit Ctrl+B I get the following error:
How should I proceed?

Sublime Build system for c++ in linux allowing input from file

I am using sublime in linux I am trying to compile and run my c++ program from sublime directly with INPUT taken from a file rather than STDIN.
Please help me with the code to be written in sublime build-file.
I got this code but its not working i think its for windows not for linux:
{
"cmd" : ["g++", "$file_name", "-o", "${file_base_name}.exe"],
"selector" : "source.c",
"shell":true,
"working_dir" : "$file_path",
"variants": [
{
"cmd": ["${file_base_name}" , "<" , "input.txt"],
"shell": true,
"name": "Run",
"working_dir" : "$file_path"
}
]
}
This is the final code which one needs to write in build system of sublime to compile and run taking input from a file.
{
"cmd": ["g++ -Wall ${file} -o ${file_base_name}"],
"working_dir": "${file_path}",
"selector": "source.c++",
"shell": true,
"working_dir" : "$file_path",
"variants": [
{
"cmd": [ "${file_path}/${file_base_name}<input.txt"],
"shell": true,
"name": "Run",
"working_dir" : "$file_path"
}
]
}
Thanks a lot MattDMo.
I suspect the reason it's not working is because g++ is creating a .exe file, and the build system is only looking for the source.c scope, whereas your code may be source.c++. Change the first two lines to the following:
"cmd" : ["g++", "$file", "-o", "${file_path}/${file_base_name}"],
"selector" : "source.c, source.c++",
and you should be all set.
I'll just add a config I use to load input from the file and display output in Sublime console ("Run in") or send output to other file ("Run in out"). Maybe someone will find it useful. (works for both Windows and Ubuntu)
{
"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 in",
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\" <$file_base_name.in"
},
{
"name": "Run in out",
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\" <$file_base_name.in >$file_base_name.txt"
}
]
}

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).