sublime custom build command, how to? - sublimetext2

I have a program, which is using what they called wmake to build the code and it's very convenient. Suppose I have a folder and a C++ file: /path/to/file.C, all I have to do is go to /path/to folder and then type the wmake command and return and all is set.
When I am using sublimetext, I would like to open this file.C file and then ctrl+B to build it, but it doesn't work. Currently I customized a build system like:
{
"cmd": "wmake"
}
the error shows as
[Errno 2] No such file or directory
[cmd: wmake]
[dir: /path/to/file.C]
[path: /home/meee/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin]
[Finished]
Anyone knows how to customize a build system in sublimetext2? I read the online mannual but still have no clue. Thanks
My aim
All I want to do is to get the same effect as I type in shell window a simple
wmake /path/to
Edit-1
I tried this, it's not working either, the same error. I dont understand why "no such file"?
{
"cmd": "wmake",
"selector" : "source.C",
"shell": false,
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "wmake '${file_path}'"]
}
]
}
Edit-2
I tried using full path of wmake, and the error complains environment variable $WM_OPTIONS not set. So in shell, every time the ~/.bashrc is auto loaded, and to initialize all the environment variables, but this is not so in Sublime!!!!!!!!!!!!! What should I do???
{
"cmd": "/fullpath/to/wmake",
"selector" : "source.C",
"shell": false,
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "/fullpath/to/wmake '${file_path}'"]
}
]
}

Your build command isn't complete. See my customized C build:
{
"cmd" : ["/usr/local/gfortran/bin/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", "/usr/local/gfortran/bin/gcc '${file}' -lgsl -lgslcblas -lm -Wall -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}

Related

gfortran linking and compiling subprograms in Visual Studio Code

I would like to compile and run fortran subprograms using Visual Studio code.
When I try debugging the code, I get an error stating that the "prelaunch task 'gfortran' terminated with exit code 1", with the following console message:
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
The terminal process "C:\MinGW\bin\gfortran.exe '-g', 'D:\......\params.f95', '-o', 'D:\.......\params.exe'" terminated with exit code: 1.
When I click 'show errors' it says that 'no problems have been detected in the worskpace so far'
My json file configurations for the folder are as follows:
Launch.json
{
"version": "2.0.0",
"configurations": [
{
"name": "Fortran Launch (GDB)",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x86",
"program": "${workspaceRoot}\\${fileBasenameNoExtension}.exe",
"miDebuggerPath": "gdb.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"externalConsole": true,
"preLaunchTask": "gfortran"
}
]
}
tasks.json
{
"version": "2.0.0",
"command": "gfortran",
"args": [
"-g",
"${file}",
"-o",
"${workspaceRoot}\\${fileBasenameNoExtension}.exe"
]
}
I tried many of the fixes found from the web, such as changing the default setting to save file before run, reinstalling gfortran etc., but to no avail. When I try compiling from the command prompt, I do not have any errors, but when I use the flag -g, I have the same error about 'undefined reference to WinMain#16'. Also, I have no problem using the settings to run a single fortran code (without subprograms).
I have a Windows-32 architecture, and I have used MinGW to install gfortran. I have set the System Environment Variable 'Path' to include this folder.
I hope the problem is clear, please help me with this.

How to fix "/bin/bash: [command] command not found" after setting up tasks.json and c_cpp_properties.json for C++ on Windows 10 VS Code?

I have configured my task.json and c_cpp_properties.json so that I may compile my main.cpp program. In order to proceed, I must press
Ctrl + Shift + B
As soon as I do a terminal pops up and alters me of an error:
Executing task in folder C++: C:\MinGW\bin\g++.exe -g main.cpp -o c:\Users\Me\Desktop\C++\.vscode\tasks.exe <
/bin/bash: C:MinGWbing++.exe: command not found
The terminal process terminated with exit code: 127
Terminal will be reused by tasks, press any key to close it.
I don't why this is happening since I've already checked that MinGW is installed in my computer with the correct PATH. To ensure that I do I typed the following in the terminal:
g++ --version
g++ (MinGW.org GCC-8.2.0-3) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
I also checked the path according to this figure
The only closest problem related to mine is in this Github link. I've also already tried changing the file directory shown in the code below using this thread but I still encounter this error.
Here are my JSON files which are inside my .vscode file:
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"main.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17134.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\\MinGW\\lib\\gcc\\mingw32\\8.2.0\\include\\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
I should expect to see a ".exe" after compiling but I can't due to the error.
After spending two days messing around with this I've finally able to correct setup C++ on VS Code and resolved the error.
According to the png image from above, I've included "C:\MinGW\bin" within the user variable "Path" under the dialogue box "User variables for Me". After a simple restart on my computer, I was able to build my project (Shift + Ctrl + B) with no problems.

Enter Input to sublime text

I am using sublime text 2 as the editor for my programs and using this code
{ "cmd": ["g++", "$file", "-o", "$file_base_name"],
"selector": "source.c++", "working_dir": "$file_path",
"variants": [ { "name": "Run", "cmd": ["g++", "$file", "-o", "$file_base_name", "&&", "$file_path/$file_base_name"], "shell": true } ]
}
I am able to run the c++ programs but unable to use test inputs in it.
How do I do that...
P.S. I don't wanna take inputs from any file but give to the console itself.

Sublime Text won't output Java println statements in main method

my Sublime Text javac build settings don't work for outputs like System.out.println statements in the main method.
I am using this sublime-build (javac):
{
"cmd": ["javac", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
"working_dir": "${project_path:${file_path}}",
"variants": [
{
"name": "Run",
"cmd": ["java", "$file_name"],
"shell": true,
"env": {"CLASSPATH": "/path/to/jar/files:/path/to/more/jars"}
}
]
}
Changing "cmd" to
"cmd": ["javac \"$file_name\" && java \"$file_base_name\""]
won't work either. But it compiles correctly and has a correct output on my bash command line.
Any thoughts?
Thanks in advance!
Nevermind, I got it:
That's the magic line missing:
"cmd": ["sh", "-c", "javac $file_base_name.java && java $file_base_name"],

folder path in sublime text build system

My sublime project looks like this:
{
"folders":
[
{
"folder_exclude_patterns":
[
".bzr",
"build",
"webapps",
"work",
".settings"
],
"path": "/home/charles/project/Editor/trunk"
}
],
"settings":
{
"build_on_save": true,
"filename_filter": "\\.(java)$",
"tab_size": 4,
"translate_tabs_to_spaces": false
},
"build_systems":
[
{
"name": "compile",
"cmd": ["ant", "-f", "dev.xml", "compile"]
}
]
}
When I save a file the console says:
Buildfile: dev.xml does not exist!
Build failed
[Finished in 0.2s with exit code 1]
I know that I need to put something before dev.xml but I don't know what.
I found some possibilities here: http://sublimetext.info/docs/en/reference/build_systems.html#variables
But What I need is the folder path "/home/charles/project/Editor/trunk" in my case...
Any idea how I can achieve this?
You are missing "working_dir" in your "build_systems" setup. The example below will use the directory that holds the sublime project file as the build starting directory.
"build_systems":
[
{
"name": "compile",
"working_dir": "${project_path}",
"cmd": ["ant", "-f", "dev.xml", "compile"]
}
]
More information can be found at: http://www.sublimetext.com/docs/2/projects.html