How to edit Sublime Text build settings? - sublimetext3

I want to enable -std=gnu++11 in Sublime Text 3's C++ Single File build on Ubuntu 12.04.
I have already upgraded the tool chain to the latest g++ and do not want to see the following error on every build:
error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
I browsed to /home/myuname/.config/sublime-text-3 but cannot find any file to edit.
How can I edit the build settings?

edited
My original answer works, but there's a much better way of doing this, by creating your own build system. This use case is exactly why the feature is there.
Go to Tools → Build System → New Build System… (all the way at the bottom) and enter the contents below. Save as C++ 11 Single File.sublime-build, and it will now be accessible in the build system menu. Select it, hit CtrlB to build, and then hit CtrlShiftB to run the resulting program. Or you can use a Build and Run option and call it by hitting CtrlB, then selecting that option.
{
"cmd": ["g++", "-std=gnu++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": ["${file_path}/${file_base_name}"]
},
{
"name": "Build and Run",
"cmd": ["g++ -std=gnu++11 ${file} -o ${file_path}/${file_base_name} && ${file_path}/${file_base_name}"],
"shell": true
}
]
}
If you need to edit it in the future, the file is in the User folder of Packages. The Packages directory is the one opened when selecting Preferences → Browse Packages…:
Linux: ~/.config/sublime-text-3/Packages or ~/.config/sublime-text/Packages
OS X: ~/Library/Application Support/Sublime Text 3/Packages or ~/Library/Application Support/Sublime Text/Packages
Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages or C:\Users\YourUserName\AppData\Roaming\Sublime Text\Packages
Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages InstallationFolder\Sublime Text\Data\Packages
The exact path depends on version and whether or not you upgraded from Sublime Text 3.

In my case, the problem is that in Windows, ST3 was calling py instead of python which was the default. If you change python in "cmd": ["python", "-u", "$file"] for your local python interpreter, the new system should work.
{
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
"windows": {
"cmd": ["python", "-u", "$file"],
},
"variants":
[
{
"name": "Syntax Check",
"cmd": ["python3", "-m", "py_compile", "$file"],
"windows": {
"cmd": ["py", "-m", "py_compile", "$file"],
}
}
]
}

Related

CMake Linux - don't get executable

I'm using CMake with Visual Studio 2019 to build an executable with the gcc compiler from a small C-program by using an Ubuntu in a Docker container. My problem is now, that I don't get an executable although I don't get any error during the building process.
A manual build on the command line with gcc -o CMakeExec CMakeExec.c works correct.
Here is my config:
CMakeExec.h
#pragma once
#include <stdio.h>
CMakeExec.c
#include "CMakeExec.h"
int main()
{
printf("This is a test!");
return 0;
}
First CMakeList.txt
cmake_minimum_required (VERSION 3.8)
add_executable (CMakeExec "CMakeExec.c" "CMakeExec.h")
Second CMakeList.txt
cmake_minimum_required (VERSION 3.8)
project ("CMakeExec")
add_subdirectory ("CMakeExec")
CMakeSettings.json
{
"name": "Linux-GCC-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"cmakeExecutable": "cmake",
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "linux_x64" ],
"remoteMachineName": "-970746741;localhost (username=test, port=5000, authentication=Password)",
"remoteCMakeListsRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/src",
"remoteBuildRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/build/${name}",
"remoteInstallRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/install/${name}",
"remoteCopySources": true,
"rsyncCommandArgs": "-t --delete --delete-excluded",
"remoteCopyBuildOutput": false,
"remoteCopySourcesMethod": "rsync",
"addressSanitizerRuntimeFlags": "detect_leaks=0",
"variables": []
}
Dockerfile
# our local base image
FROM ubuntu
LABEL description="Container for use with Visual Studio"
# install build dependencies
RUN apt-get update && apt-get install -y g++ rsync zip openssh-server make
# configure SSH for communication with Visual Studio
RUN mkdir -p /var/run/sshd
RUN echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config && \
ssh-keygen -A
# expose port 22
EXPOSE 22
Output from the Visual Studio
Copying files to the remote machine.
Starting copying files to remote machine.
[rsync] rsync -t --delete --delete-excluded -v -r --exclude=.vs --exclude=.git --exclude=out -8 "." rsync://test#localhost:51754/-home-test-.vs-CMakeExec-369e0150-0280-45f1-b4c9-244852742d47-src
[rsync] sending incremental file list
[rsync] CMakeSettings.json
[rsync]
[rsync] sent 291 bytes received 54 bytes 690.00 bytes/sec
[rsync] total size is 2,765 speedup is 8.01
Finished copying files (elapsed time 00h:00m:02s:371ms).
CMake generation started for configuration: 'Linux-GCC-Debug'.
Found cmake executable at /usr/bin/cmake.
/usr/bin/cmake -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="$HOME/.vs/CMakeExec/369e0150-0280-45f1-b4c9-244852742d47/out/install/Linux-GCC-Debug" "/home/test/.vs/CMakeExec/369e0150-0280-45f1-b4c9-244852742d47/src/CMakeLists.txt";
[CMake] -- Configuring done
[CMake] -- Generating done
[CMake] -- Build files have been written to: /home/test/.vs/CMakeExec/369e0150-0280-45f1-b4c9-244852742d47/out/build/Linux-GCC-Debug
Extracted CMake variables.
Extracted source files and headers.
Extracted code model.
Extracted includes paths.
CMake generation finished.
I hope that anyone has an idea what is missing.

/bin/sh: tsc: command not found

I am using the Visual Studio Code to work with TypeScript.
I created the tasks.json file in order to compile the ts files, but I getting this error when I run it:
/bin/sh: tsc: command not found
The terminal process terminated with exit code: 127
This is my tasks.json file:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [
"$tsc"
]
}
]
}
Does anyone know what is this?
I am using Linux Mint.
It is not duplicated one of tsc is not recognized as internal or external command
I already tried those steps but it did not worked.
This is my tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true
}
}
Using the terminal when I type node -v it is showing this:
v11.2.0
tsc -v:
Version 3.1.6
It appears that the binary tsc is not in your path. Have the package(s) for TypeScript been installed? This is probably a duplicate of tsc is not recognized as internal or external command

g++ is not recognised as an internal or external command in Sublime text

I have set the system path properly and have tried doing this several times. But I keep getting the error that
g++ is not recognized as an internal or external command
The full error message is:
'g++' is not recognized as an internal or external command, operable
program or batch file. [Finished in 0.2s with exit code 1] [shell_cmd:
g++ "C:\Users\NIGHTMARE\Documents\test.c" -o
"C:\Users\NIGHTMARE\Documents/test" &&
"C:\Users\NIGHTMARE\Documents/test"] [dir:
C:\Users\NIGHTMARE\Documents] [path:
C:\Python27\;C:\Python27\Scripts;C:\ProgramData\Oracle\Java\javapath;C:\Program
Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS
Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program
Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program
Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files
(x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program
Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files
(x86)\GtkSharp\2.12\bin;C:\mingw32;C:\Users\NIGHTMARE\AppData\Local\Microsoft\WindowsAppsC:\mingw32;]
What should I do to solve this problem?
I have met a similar problem when I tried to use pandoc to convert markdown to pdf files. The pandoc path has been properly set up: I can use pandoc command in system cmd.
I wrote a simple build system in sublime text to use pandoc to compile my file but similar error occurred. After consulting the sublime documentation, I have found that we can set a path variable in the custom build system:
path Optional.
PATH used by the cmd subprocess.
Use this option to add directories to PATH without having to modify
your system’s settings.Environmental variables will be expanded.
The following is a working build system that works for me:
{
"shell_cmd": "pandoc --pdf-engine=xelatex -f gfm --highlight-style zenburn -Vurlcolor=NavyBlue -V CJKmainfont=\"Source Han Serif SC\" \"${file}\" -o \"${file_path}/${file_base_name}.pdf\" ",
"path": "C:/Users/east/AppData/Local/Pandoc/;%PATH%",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "text.html.markdown",
"variants":
[
{
"name": "Convert to PDF and Preview",
"shell_cmd": "pandoc --pdf-engine=xelatex -f gfm --highlight-style zenburn -Vurlcolor=NavyBlue -V CJKmainfont=\"Source Han Serif SC\" \"${file}\" -o \"${file_path}/${file_base_name}.pdf\" &&SumatraPDF \"${file_path}/${file_base_name}.pdf\" ",
"path": "C:/Users/east/AppData/Local/Pandoc/;%PATH%",
// "shell_cmd": "start \"$file_base_name\" call $file_base_name"
}
]
}
You have to adapt it to your case, just change the path to directory where your g++ command resides which is followed by system path %PATH%.
After using above build system, I no longer met this problem. Let me know if it works for you.

How do I use TypeScript 1.6 with Visual Studio Code to get generators support?

I've been targeting ES6 for a while in Visual Studio Code, but when I try to switch to TypeScript, it throws errors such as:
Generators are only available when targeting ECMAScript 6
But my tsconfig.json does have the ES6 target:
{
"compilerOptions": {
"target": "ES6",
"module": "amd",
"sourceMap": true
}
}
So I tried npm install -g typescript#1.6.0-beta but it looks like VSCode doesn't care.
Generators are not currently supported.
How can I get TypeScript and generators to work properly together in VS Code?
Update
Changing typescript.tsdk to the 1.6 binary seems to fix IntelliSense errors, but this tasks.json still prints out error TS1220: Generators are only available when targeting ECMAScript 6 or higher.:
"version": "0.1.0",
"command": "/usr/local/lib/node_modules/typescript/bin/tsc",
"showOutput": "silent",
"windows": {"command": "tsc.exe"},
"isShellCommand": true,
"args": ["app.ts"],
"problemMatcher": "$tsc"
However, /usr/local/lib/node_modules/typescript/bin/tsc --target ES6 app.ts used manually in the terminal does work.
I know now!
1. IntelliSense
You can use the typescript.tsdk setting to point VSCode to TypeScript binaries. Upgrade your TypeScript to 1.6 and set the location properly.
You can do it either in your user/workspace settings, or per project in the .vscode/settings.json file. OS X example:
"typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib"
2. Compiler
You also need to make sure your .vscode/tasks.json points to the new binary and makes the compiler operate in Explicit project mode, i.e. use tsconfig.json instead of taking a list of files to compile as an argument.
{
"version": "0.1.0",
"command": "/usr/local/lib/node_modules/typescript/bin/tsc",
"showOutput": "silent",
"windows": {"command": "tsc.exe"},
"isShellCommand": true,
"args": [], //do not pass any files to the compiler. This way it will use tsconfig.json where you can set target: "ES6"
"problemMatcher": "$tsc"
}
And finally tsconfig.json (in the project's root directory):
{
"compilerOptions": {
"target": "ES6", //The key, of course.
"module": "amd",
"sourceMap": true
},
"exclude": [
"node_modules",
".vscode"
]
}
Restart the editor afterwards!
You can change your user settings in VS Code and set "typescript.tsdk" to a custom location .
If you install the nightly (npm install -g typescript#next), you can point to that version of TypeScript's lib folder.
More
Reasons and setup instructions for using ts latest are covered here : https://basarat.gitbooks.io/typescript/content/docs/getting-started.html#typescript-version

node-gyp configure to release mode

Hi I am trying to compile a node_modules as Release mode, but I could not successfully configure as Release mode.
I ran node-gyp configure; the configure.gypi generated
# Do not edit. File was generated by node-gyp's "configure" step {
"target_defaults": {
"cflags": [],
**"default_configuration": "Debug",**
"defines": [],
"include_dirs": [],
"libraries": [] },
I tried with -DBUILDTYPE=Release and BUILDTYPE=Release but not successfully
Default should be Release.
Try node-gyp configure --release

Resources