I found a build system for c++ for st3 and it is pretty good but there is a small kink it does not compile unless a .exe file with the source file name exists in the directory. Any idea on how to automate it with the build to create a file if it does not exist or continue?
"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}"
}
That should run regardless, as the build will create a .exe file with the source name in the current directory. If for some reason it isn't working, remove everything on line 2 after "-Wall" so that it looks like this:
"windows":
{
"cmd": ["g++", "$file_name","-o", "${file_base_name}.exe", "-lm", "-Wall"]
},
"selector": "source.c++",
"shell": true,
"working_dir": "${file_path}"
}
Related
How do I run C++11 in Sublime Text 3?
I found this and this works, but I want it to be able to open cmd each run.
(1)
{
"shell_cmd": "g++ -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",
"shell_cmd": "g++ -std=c++11 \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
}
]
}
Like this one:
(2)
{
"cmd":
[
"g++", "-Wall", "-ansi", "-pedantic-errors", "$file_name", "-o",
"${file_base_name}.exe", "&&", "start",
"cmd", "/k" , "$file_base_name"
],
"selector": "source.cpp",
"working_dir": "${file_path}",
"shell": true
}
The problem with (1) is it runs with the console inside Sublime Text 3, I don't want that, unfortunately.
The problem with (2) is it runs well and it opens CMD each time, which is what I need, but it's on C++98. When I need C++11.
So, is there a way to modify any one of these build systems so that I can run C++11 and make it open CMD every run (instead of running it on the console)? Thanks.
I was able to figure it out with a little bit of tinkering involved.
{
"shell_cmd": "g++ -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",
"shell_cmd": "g++ -std=c++11 \"${file}\" -o \"${file_path}/${file_base_name}\" && start cmd /k \"${file_path}/${file_base_name}\""
}
]
}
I'm debugging a remote program using gdb on my host computer and gdbserver on my remote.
Everything works fine except that I cannot figure out how to show stdout and stderror on the VS Code terminal.
I have created a launch.json which sets up the debugging environment. The launch json calls a tasks using the preLaunchTask option:
...
"MIMode": "gdb",
"targetArchitecture": "arm64",
"preLaunchTask": "debug_preparation",
"miDebuggerPath": "/usr/bin/gdb-multiarch",
...
The debug_preparation task looks like the following:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "debug_preparation",
"command": "sh",
"args": ["start_debug_session.sh"],
"type": "shell",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new",
"showReuseMessage": false,
"clear": false,
"close": false
}
}
]
}
Do you have an idea of what is missing?
Maybe, the VS Code terminal is not the right place to do so. If that's the case, I'm happy with any other option.
The only workaround that I have is to start the gdbserver on the remote with the following:
ssh -n -f $USER#$TARGETIP "sh -c 'nohup gdbserver localhost:4444 ${FULL_REMOTE_PATH} > /output/stdout.txt 2>/output/stderr.txt &'"
but it's kind of annoying to always ssh into the remote and open these files to see wath went wrong.
Hello I am following this tutorial
https://code.visualstudio.com/docs/typescript/typescript-tutorial
to debug typescript but I have encountered error as shown in the screenshot.
If I choose debug anyway, the debugger works but I cant set any breakpoint. I suspect it has something to do with failing to set up the task file.
Any advise guys?
I had a similar problem. In my case, the tsconfig.json file was not in the main folder, but in a subfolder. In my case, the working configuration looked like this
{
"type": "node",
"request": "launch",
"name": "Launch server",
"program": "${workspaceFolder}/server/index.ts",
"preLaunchTask": "tsc: build - server/tsconfig.json",
"outFiles": ["${workspaceFolder}/out/**/*.js"]
}
Task tsc: build - tsconfig.json by default comes from VSCode when it detects the existence of tsconfig.json. Based on your screenshot, I can tell that you already have the file. So, it is odd if it can't be detected.
Please make sure the file content of tsconfig.json is valid.
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "out",
"sourceMap": true
}
}
Also to check whether the tasks are exist, you can choose menu Terminal -> Run Build Task or press Shift + Command + B on MacOS. If correct, you can see two tasks available there as the image below.
Otherwise, there must be something wrong with the steps. Perhaps, there is an extra space in preLaunchTask. For reference, I also copy paste my launch.json here.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/helloworld.ts",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/out/**/*.js"
]
}
]
}
For other language users, the tsc: build command maybe be another command, such as tsc: 构建 in Chinese.
my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/index.ts",
"preLaunchTask": "tsc: 构建 - tsconfig.json",
"outFiles": [
"${workspaceFolder}/out/**/*.js"
]
}
]
}
When you Ctrl+Shift+B terminal will run Run Build Task.. You'll see in the terminal
">Executing task: tsc -p c:....
Terminal will be reused by tasks, press any key to close it."
Then after that double click a ts file and press F5 you will have to select at which environment do you want your ts file to run and then you will see the output in the debug console.
because it does not find path of tsconfig file....
see your folder structure whether the structure contains multiple same folder with same name...so y debugger confused to find path....so make sure the devlopement folder which you work on has proper path with unique name no same name with its parent folder and contains tsconfig files...
This happens also if the Extension Host crashed. This prevents the task engine from finding the requested task. Usually, you should see a message in the toaster where you can immediately restart the Extension Host. After that the debugger and tasks work.
For Ubuntu Linux 20.04 LTS (but may well be the same on other OS's) what got preLaunchTask working for me, was using both a local tasks.json and launch.json
So my folder structure (pre-build) is:
.vscode/launch.json
.vscode/tasks.json
dist
src/index.ts
package.json
tsconfig.json
My launch.json contains:
{
"configurations": [
{
"type": "node",
"request": "launch",
"name": "TS preLaunchTask-build",
"program": "${file}",
"preLaunchTask": "tsc: build",
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"skipFiles": [
"<node_internals>/**", "node_modules",
]
},
]
}
My tasks.json contains:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"command": "echo hello yes working!",
"problemMatcher": [],
"label": "myTask"
},
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": ["$tsc"],
"group": "build",
"label": "tsc: build"
},
]
}
And my tsconfig.json contains:
{
"compilerOptions": {
"outDir": "./dist",
"sourceMap": true,
"target": "es5",
"module": "commonjs"
},
"include": [
"src/**/*"
]
}
Usage: whilst within the index.ts just hit F5 with a breakpoint set
I have also included another task, "myTask" you can change the preLaunchTask line in your launch.json to: "preLaunchTask": "myTask", (where it will output some text to console to verify preLaunchTask is now working)
That way, if you still have issues, you can see if the issue is in your tsconfig setup, or if it's a preTaskLaunch setup issue.
(I would have thought it should have resolved this itself, but apparently not at the current time of writing anyway - but does force the advantage (for me) of committing debug config to the repo on project basis rather than global config)
Be sure to check the exact structure/spelling of Task by pressing Ctrl+Shift+B (on Windows) and Cmd+Shift+B(on Mac).
In my case, it was tsc: build - projectName/tsconfig.json
I have the following directories:
.vscode
-- launch.json
-- tasks.json
build
-- script
-- -- main.js
-- -- main.js.map
node_modules
src
-- script
-- -- main.ts
-- typings
-- tsd.json
gulpfile.js
And of course other things like readmes and the content of node_modules etc.
Anyway, my launch.json looks as following:
{
"version": "0.2.0",
"configurations": [
{
"name": "debug",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/src/script/main.ts",
"stopOnEntry": true,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"preLaunchTask": "build",
"outDir": "${workspaceRoot}/build/script/",
"sourceMaps": true
},
{
"name": "attach",
"type": "node",
"request": "attach",
"port": 5858
}
]}
and my gulpfile for building the typescript as follows:
gulp.task('typescript', function() {
gulp.src('./src/script/**/*.ts')
.pipe(ts({
noImplicitAny: true,
target: 'ES6',
module: 'commonjs',
removeComments: true
}))
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./build/script/'));
});
Now back to my problem:
As said in the title, VS Code starts the debugger and it actually works but it debugs the main.js file instead of the main.ts file.
As far as I understand I have to set main.ts as the program parameter and the directory containing the js files as the outDir parameter.
At the moment I am somewhat stuck as I feel like my configuration is correct but for some reason, well obviously, it isn't.
Maybe someone can see the mistake I have made :)
I had a similar problem. First, try to execute the js file from your launch.json.
Then, you also need a tsconfig.json file in the root of the project, even if you compile with gulp. This file has a "sourceMap" parameter that needs to be set to true in order to be able to debug ts files with source maps.
A sample tsconfig.json file:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
So I have this build file
{
"cmd": ["coffee", "-c", "$file"],
"selector": "source.coffee",
"path": "C:\\Users\\Miles\\node_modules\\coffee-script\\bin",
"working_dir": "$project_path"
}
And it keeps on returning the error
[Error 2] The system cannot find the file specified
I have looked for a few days and and all I can find is unix based paths.
I know this is most likely trivial but it has been bugging be for a while
after a lot of tinkering this works fine.
{
"cmd": ["coffee.cmd", "-c", "$file"],
"selector": "source.coffee",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"path": "$HOME/bin:/usr/local/bin:$PATH",
"working_dir": "$project_path"
}