Sublime Text no build output - c++

Using build option does not give any output except of
[Finished in 0.4s]
I didn't configure any c++.sublime-build file, I just installed C++ compiler and added it to the system path. It should work out of the box, but it is not. I also use Pawn language very often, but I had to configure my pawn.sublime-build file in order to work. There is a similar problem, after building if there are some errors it says:
[Finished in 0.4s]
But if the code has no errors, it says:
Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team
Header size: 836 bytes
Code size: 5048 bytes
Data size: 2148 bytes
Stack/heap size: 16384 bytes; estimated max. usage=883 cells (3532 bytes)
Total requirements: 24416 bytes
Done.
[Finished in 0.1s]
It would by nice if sublime could just show the output from compiler.
Here's my Pawn.sublime-build
{
"cmd": ["amxxpc.exe", "$file"],
// "cmd": ["compile.exe"],
// "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"file_regex": "(.*)\\((\\d+)\\)\\s*:\\s*()(.*)",
"selector": ["source.pwn", "source.pawn", "source.sma", "source.inc"],
"path": "Extensions\\pawn\\"
}
I tried diffrent versions of the "file_regex" and also without it, just like in tutorials, but it just doesn't show output if code has an error.
On the other hand, Python shows up an output, like this:
print"test")
^
SyntaxError: invalid syntax
[Finished in 0.2s with exit code 1]
[shell_cmd: python -u "C:\Users\Michał\OneDrive\Documents\test.py"]
[dir: C:\Users\Michał\OneDrive\Documents]
[path: C:\Program Files (x86)\ActiveState Komodo Edit 9\;C:\Python34\;C:\Python34\Scripts;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\MinGW\bin]
And here's output with corrected code:
test
[Finished in 0.1s]
How can I get output from C++ and Pawn files?
What I am doing wrong?
I use MinGW for C++ and amxxpc.exe (AMX MOD X COMPILER) for pawn.
Thank you in advance for any solution and sorry for my english. I'm from Poland.

Open up Sublime Text 2 and go to Tools -> Build System -> New Build System...
Enter the following:
{
"cmd": ["pawncc.exe", "-i includes", "$file", "-;+"],
"path": "C:/path/to/pawno/folder"
}
Of course you need to replace the path
Save this file and close Sublime Text 2
Now navigate to AppData/Roaming/Sublime Text 2/Packages/User
Open up the .sublime-keymap file based on your operating system
Enter the following (this example is for the Windows file):
[
{ "keys": ["f5"], "command": "build" }
]
You can change f5 to another key if you wish
Save and reopen Sublime Text 2
Now go to Tools -> Build System
Click on the name of the build you created
`

Related

Sublime Text 3 intel oneAPI Fortran build system

Has anyone figured out how to write the build system for the oneAPI Fortran compiler?
Previously, i was using Parallel Studio XE ifort, and i managed to get it working using the solution here:
{
"cmd": ["cmd", "/e:on", "/v:on", "/k", "ipsxe-comp-vars intel64 vs2013 && ifort ${file}"],
"file_regex": "^.*\\\\([0-9A-Za-z_]+\\.[A-Za-z0-9]+)\\(([0-9]+)\\):[ ]+error[ ]+#([0-9]+):[ ]+(.*)$",
"working_dir":"${file_path}",
"selector":"source.f ,source.for ,source.ftn ,source.f90 ,source.fpp ,source.i ,source.i90",
"encoding":"cp936",
"path":"C:\\Program Files (x86)\\IntelSWTools\\compilers_and_libraries_2017.4.210\\windows\\bin;${path}",
"variants":
[
{
"name": "Run",
"cmd": ["cmd", "/e:on", "/v:on", "/c", "ipsxe-comp-vars intel64 vs2013 && ifort ${file} && ${file_base_name}"]
}
]
}
I tried changing the paths to the new ones but it doesn't work. I get the following error:
"ipsxe-comp-vars" is not recognized as an internal or external command,
program o executable.
I found the answer. Explanation below. Posting the working build system here for visibility.
This should be the build system:
{
"cmd": ["cmd", "/e:on", "/v:on", "/S", "/k", "C:\\\"Program Files (x86)\"\\Intel\\oneAPI\\setvars.bat intel64 vs2022 && ifort ${file}"],
"file_regex": "^.*\\\\([0-9A-Za-z_]+\\.[A-Za-z0-9]+)\\(([0-9]+)\\):[ ]+error[ ]+#([0-9]+):[ ]+(.*)$",
"working_dir":"${file_path}",
"selector":"source.f ,source.for ,source.ftn ,source.f90 ,source.fpp ,source.i ,source.i90",
"encoding":"cp936",
"path":"C:\\Program Files (x86)\\Intel\\oneAPI\\compiler\\latest\\windows\\bin\\intel64;${path}",
"variants":
[
{
"name": "Run",
"cmd": ["cmd", "/e:on", "/v:on", "/s", "/c", "C:\\\"Program Files (x86)\"\\Intel\\oneAPI\\setvars.bat intel64 vs2022 && ifort ${file} && ${file_base_name}"]
}
]
}
Why the problem happens
For starters, ipsxe-comp-vars is a batch file which when run, sets up environment variables required to execute the intel compilers. This file is specific to Intel Parallel Studio XE (IPSXE). Now, when installing IPSXE, it would add this batch file to your PATH, meaning you could simply call ipsxe-comp-vars from any directory to set up the required environment variables.
Intel oneAPI has a differently named file, that essentially does the same thing, called setvars.bat. This file is stored in:
C:\Program Files (x86)\Intel\oneAPI\setvars.bat
So, at first it seems that calling ipsxe-comp-vars fails because the file is named differently. However, unlike IPSXE did with ipsxe-comp-vars, oneAPI does not add setvars to PATH, so you cannot simply call setvars, you have to usethe full path.
How to solve it
With IPSXE, you could call ipsxe-comp-vars and it would run the batch file that sets up environment variables, but with oneAPI either you add the file to PATH (not reccomended because it has a generic name), or you use the full path when calling it (same as above):
C:\Program Files (x86)\Intel\oneAPI\setvars.bat
Now, because you have to plug this in into the build system config, you need to format it correctly. ST runs the commands in a cmd.exe, so you have to use the correct options and format the path in a way that cmd can understand it:
options (you can get a full list by opening a cmd prompt, typing cmd /? and hitting return):
- /e:on Enables command extensions
- /v:on Enables extension of environment variables
- /s Modifies how the string following a /c or /k is read
- /k Executes the string command and continues
The path to the setvars.bat file must be formatted as follows:
C:\\\"Program Files (x86)\"\\Intel\\oneAPI\\setvars.bat
Each \ separating dirs needs to be escaped (using \ as well)
needs to be enclosed in double quotes, since it contains a whitespace. Each double quote needs to escaped as well (once again with )
The following options are specific to the setvars.bat file:
- intel64 specifies 64-bit configuration
- vs2022 specifies Visual Studio 2022 as the developer cmd or
powershell version to use
Finally, ifort is called on the current file with ifort ${file}
Additionally, the build system is completed with a variant "Run". This variant runs the output file once it has been compiled(&& ${file_base_name}), and will show the output in the Sublime Text 3 console (does not accept inputs, if anyone knows how to setup up sublimeREPL for Fortran please tell me)

Not able read from input output files in Sublime Text 3

I have successfully installed MinGW and have tried running cpp programs from command prompt and it runs perfectly. In Sublime I tried using default build system 'C++ Single File', it prints simple statements in the console below but it cannot take input. After building the programs with 'cin' commands the program does not show any output and I try giving input in the console below and press ENTER but nothing happens. Then I found a method of using 'freopen' command to take input from a file and output to a different file. But the programs runs successfully but doesn't output anything in the output file. Same problem -- mingw64 + sublime 3 input output files not working
After this I tried many other build files I found on web but none of them work.
{
"cmd": ["g++.exe", "-std=c++17", "${file}",
"-o", "${file_base_name}.exe",
"&&", "${file_base_name}.exe<input.in>output.out"],
"shell":true,
"working_dir":"$file_path",
"selector":"source.cpp"
}
The output.out file is always empty. I have input and output files in same directly and I think it is reading input correctly because when I delete the input file it gives an error that it cannot find the input file. I even tried using text files (input.txt, output.txt) after moding build system code but it doesn't work.
I have many other build codes but none of them works.
I tried running g++.exe -std=c++17 contest1a.cpp -o contest1a.exe && contest1a.exe<input.in>output.out in command prompt but the output.out file is still empty.
I replaced first line with "cmd" : ["g++ -std=c++14 $file_name -o $file_base_name && timeout 4s $file_base_name < input.in > output.out"], but it gives error because I think .exe is not suffixed which I tried adding and program runs but output is still empty.
Why is 'freopen' not working, why is any build not able to write in output file ?
So it turns out Windows defender has a new feature 'Block Folder Access' which blocked my program from modifying the output file. I wasted one day solving this issue smh

getting an access denied error while building a cpp file in sublime text

So i downloaded sublime text and installed mingw compiler. I have verified through cmd prompt that mingw is installed correctly. I added the environment path to my compiler in settings.
I created a new build system on sublime text:
{
"cmd": ["g++.exe","-std=c++17", "${file}", "-o", "${file_base_name}.exe", "&&" , "${file_base_name}.exe<inputf.in>outputf.in"],
"shell":true,
"working_dir":"$file_path",
"selector":"source.cpp"
}
Above system i took from this site: https://blog.codingblocks.com/2019/setting-up-a-c-competitive-programming-environment/
Basically it takes input from inputf.in and shows output at outputf.in
When i write my program of a simple printing of "hello world" and try to build using Cntrl + B, i get the following error.
Access is denied.
[Finished in 1.1s]
Any help would be appreciated. Thanku
EDIT: It was my antivirus. Thanku to all who answered. :D

Unexpected fail when running C++ code with Sublime Text 2 on Windows8

I just begin to use sublime text 2 on my laptop. I want to compile and run C++ code using sublime text 2.
I installed MinGW and g++, and changed the path environment to include the path where MinGW was installed.
I opened sublime text 2 and wrote a simple C++ program, named test.c, to do the test.
#include "stdio.h"
# test.c
int main()
{
printf("hello");
}
I did Ctrl+B to compile and got the message:
[Finished in 0.8s].
I used Ctrl+Shift+B to run it and got the following message.
[Error 2] The system cannot find the file specified
[cmd: [u'bash', u'-c', u"g++ 'C:\Users\me\Desktop\test.c' -o 'C:\Users\me\Desktop/test' && 'C:\Users\me\Desktop/test'"]]
[dir: C:\Users\me\Desktop]
[path: C:\Python27\Lib\site-packages\PyQt4;C:\MinGW\bin;]
[Finished]
I tried to solve this problem and did the following things.
i. Sublime Text 2 --> Tools --> Build System --> New Build System
ii. in the newly opened window in sublime, I input the following commands.
{
"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}"]
}
]
}
iii. I saved the file as gcc.sublime-build and went back to run test.c.
However, the test.exe was not run appropriately and Win8 showed this window, which says
test.exe has stopped working
A problem caused the program to stop working correctly.
Windows will close the program and notify you if a solution is available.
I got this message from sublime text after closing the window:
[Finished in 7.6s with exit code 255].
I don't why and how to fix it.
Why don't you simply install Visual Studio? It includes both compiler and code editor, so you don't need to waste your time on setting up buggy software like Sublime.

How to build and run c++ programs in Sublime Text 2, Windows 8?

I installed Codeblocks with mingw, chose default compiler, and could build and run a simple hello program without errors.
I installed Sublime Text 2, copy pasted the same hello world program:
// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
Upon building, I get the error message:
[Error 2] The system cannot find the file specified
[cmd: [u'bash', u'-c', u"g++ '' -o '/' && '/'"]]
[dir: C:\Windows\system32]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\]
[Finished]
What do I need to do in order to build and run a simple program using Sublime Text 2?
First, make sure you save the file you're working on, wherever on your drive, before building and running.
Sublime Text 2 needs g++, bash, etc in order to compile. These packages need to be installed on your computer, as per the instructions on this page:
http://mjiang.com/mec/cs244/files/Installing%20c++_g++_on_Windows.pdf
For WINDOWS:
If you have Dev C++ (Bloodshed) then,
OPEN SUBLIME TEXT 2 and creat a new file to write your code (change build system to c++ through Tools> Build System> C++ as SublimeText2 doesn't come with build-system for c)
After that, you save that file to bin folder contained in Dev-Cpp folder and press ctrl+b
If your code is correct (bug free) then you'll found a corresponding file (in .exe format) on same directory which will show you
Hello World!
REMEMBER: SUBLIME TEXT 2 is an Editor, not a COMPILER
You could use my working C++.sublime-build file for Windows:
https://gist.github.com/trietptm/4950038
just create new Build-system (TOOLS->BUILD SYSTEM->NEW BUILD SYSTEM)
{
"windows":
{
"cmd": ["g++", "$file_name","-o", "${file_base_name}.exe", "-lm", "-Wall", "&","start", "${file_base_name}.exe"]
},
"selector": "source.c++",
"shell": true,
"working_dir": "${file_path}"
}
and save it as (name_you_can_provide).sublime-build and use that build system. :)
(I assume you already have installed MingW in your computer.)
You need to go to
Preferences->Browse Packages->C++ folder->C++.sublime-build;
bring this C++.sublime build file into the sublime text editor and now paste 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 } ]
}
Hope this helps you.
You must install MinGW, then add path to MinGW to PATH variable.