I am using Visual Studio Code for the first time for programming C++ in a Linux (gnome) environment.
I have made a dummy .cpp file which asks me for an input value and then returns it in a string on the screen
However in Visual studio code I do not get an input or output screen.
I have tried in my tasks.json file to add "presentation" "reveal": "always"
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "build hello world",
"type": "shell",
"command": "g++",
"args": [
"-g", "helloworld.cpp"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always"
}
}
]
}
I didn't really find any answers that could help me anywhere. There was a "terminal": "integrated" attribute, but this one is deprecated.
Related
I'm using VS Code for running c++ code.
Whenever I Ctrl + Shift + B to build my .cpp file, an 'echo' tab pops up, which makes the entire bottom panel appear and then I am asked to "Terminal will be reused by tasks, press any key to close it."
I don't want the tab or the panel to pop up at all and want the entire build process to happen in silence, nothing pops up.
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": [
{
"label": "echo",
"type": "shell",
"command": "gcc",
"args":[
"main.cpp","-lstdc++","-o" ,"main.exe"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
This can be configured using "presentation": {...}. Following worked for me:
{
"version": "2.0.0",
"tasks": [
{
"label": "Test task",
"type": "shell",
"command": "echo Hello world",
"presentation": {
"echo": true,
"reveal": "never",
"showReuseMessage": false,
}
}
]
}
Solved by downgrading VSCode to 1.60: https://code.visualstudio.com/updates/v1_60
is there any way to connect an external compiler to VS Code?
I have a compiler delivered by the client which is located in a folder:
app\cc\linuxacu\x86_64-poky-mingw32\usr\bin\poky-linux-gnu
I would like to add it to VS Code to be able to compile the project directly in the editor. Is it possible to create a 'task' that will use the compiler from the specified path?
Additionally, I need to compile two types of files:
Makefile located under this path:
app\Makefile.mk
The C file that is currently open
app\src\device\type\src
I tried to create a task but unfortunately I can't run it properly.
Result:
The terminal process failed to launch: Starting directory (cwd)
"C:/Users/Kxk/app/Makefile.mk" does not exist.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "C/C++ LinuxARM Compiler Makefile",
"type": "shell",
"command": "C:/Users/Kxk/app/cc/linuxacu/x86_64-poky-mingw32/usr/bin/poky-linux-gnu/poky-linux-gnu-gcc",
"args": [
"-g"
],
"options": {
"cwd": "C:/Users/Kxk/app/Makefile.mk",
//"cwd": "${file}"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
]
}
From vscode GetStarted guide for C++ extension the vscode prints out the command which is being generated by tasks.json.
In my case I am trying to configure the tasks.json but the compiler is giving some errors and its really hard to debug if I cant see what was the command generated. Instead of the command the label is printed out and it looks like this:
How can I see the commands generated by tasks.json?
I am using the default tasks.json file:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": ["-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
“I’m setting up Visual Studio Code, and when I try to run my main.cpp (main.exe when executed), It is showing the error mentioned above.
From what I read about the issue online. I think it is because of wrong written in the c_cpp_properties.json file. But I can't figure out where to make the changes.
#Code:
#include <iostream>
int main()
{
std::cout<<"Hello World"<<std::endl;
}
#c_cpp_properties.json :
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\\MinGW\\lib\\gcc\\mingw32\\8.2.0\\include\\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
Error Message:
Program 'main.exe' failed to run: The specified executable is not a valid application for this OS platform.At line:1 char:1
+ .\main.exe+ ~~~~~~~~~~.
+ FullyQualifiedErrorId : NativeCommandFailed
You're getting this error because you're building on 64 bit windows machine with 32bit cpp.exe. So you're building for a different target machine.
To fix this, change your tasks.json file to point to g++.exe instead of cpp.exe.
To access your tasks.json file on windows (ctrl+shift+p) and then type "tasks"
change cpp.exe to g++.exe
I, too, faced the same error but rectified it with a simple solution
1.) First go and check your extensions whether you have installed the C/C++ by Microsoft.
2.) If not, do that first!
3.) If you have already installed, don't worry, check the version of your Visual Studio Code by clicking help in the menu bar and pressing About.
For version 2.0.0:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "g++",
"args": [
"-o",
"main",
"-g",
"main.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Run",
"type": "shell",
"command": ".\\main",
"problemMatcher": []
}
]
}
For version 1.0.0:
{
"version": "0.1.0",
"command": "make",
"isShellCommand": true,
"tasks": [
{
"taskName": "Makefile",
// Make this the default build command.
"isBuildCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
// Pass 'all' as the build target
"args": ["all"],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
4.) Check your version properly and paste the above-mentioned syntax in your tasks.json.
To go to tasks.json Do the following steps:
Press Ctrl+Shift+P.
You will see your command palette where you must type configure tasks. And select (“Tasks: Configure Task”).
You can type the above-mentioned syntax with respect to your Visual Studio Code Version.
Don't miss out the ending curly braces mentioned below the syntax
For me you just need to configure your task.json file
My tasks.json file is this:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "g++",
"args": [
"-o",
"main",
"-g",
"main.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Run",
"type": "shell",
"command": ".\\main",
"problemMatcher": []
}
]
}
Also to run the exe file the command is ".\filename" without the extension.
We can execute cpp Programs using
g++ name_of_file.cpp
./a
Or for c prgrams
gcc name_of_file.c
./a
I've been trying for hours and I can't seem to do it I've downloaded extensions and asked for help around but everything is just confusing me at this point.
I want to include the SFML libs in my project and I'm trying to use the the Visual Studio Code editor for it but it just won't comply for some reason.
A picture of what it currently looks like.
http://imgur.com/qJPlJua
I've been trying this for hours yesterday also but it just doesn't want to work.
I know the topic is a couple years old now but since I was searching for a way to link the sfml lib in vs code and I first ended up here, I thought I would share this git repo I found, which works pretty well for me so far:
https://github.com/andrew-r-king/sfml-vscode-boilerplate
I'm not using SFML 2.5.1 though, so I had to bring a small change in the c_cpp_properties.json file (I am on Ubuntu 18.04 and installed sfml through package manager)
here my c_cpp_properties.json file:
{
"configurations": [
{
"name": "Linux",
"intelliSenseMode": "gcc-x64",
"includePath": [
"${workspaceFolder}/src",
"/usr/local/include/**",
"/usr/include/**"
],
"defines": [],
"cStandard": "c11",
"cppStandard": "c++17",
"forcedInclude": [
"${workspaceFolder}/src/PCH.hpp"
]
}
],
"version": 4
}
I know this question is about two years old, but after fiddling with my own tasks to solve this problem, and came up with something. This shouldn't be the best way to do it, but this should be good for anyone that finds this answer in the future.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Compile",
"type": "shell",
"group": "build",
"command": "g++",
"args": [
"${file}",
"-o",
"${fileBasenameNoExtension}.exe",
"-IC:\\SFML-2.5.1\\include",
"-LC:\\SFML-2.5.1\\lib",
"-lsfml-graphics",
"-lsfml-window",
"-lsfml-system",
],
"problemMatcher": [
"$gcc"
]
}
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
//"showReuseMessage": true
}
}
This should work the same as the above answer. Hit CTRL+SHIFT+B to bring up the Task prompt, or look up Run task in the Command Palette (CTRL+SHIFT+P). Remember to have the .dlls of each library used in the root of the project.
Hope this helps.
I searched and I have found the solution.
In the tasks.json file, define two tasks :
"tasks": [
{
"taskName": "Compilation",
"isBuildCommand": true,
"args": ["-c", "${workspaceRoot}\\main.cpp", "-IC:\\SFML-2.4.0\\include"]
},
{
"taskName": "Liaison du fichier compilé aux bibliothèques SFML",
"args": ["${workspaceRoot}\\main.o", "-o", "sfml-app.exe", "-LC:\\SFML-2.4.0\\lib", "-lsfml-graphics", "-lsfml-window", "-lsfml-system"]
}
],
and add "suppressTaskName": true,
So it's like on Linux.
You compile with CTRL + SHIFT + B. To create the .exe file : CTRL+SHIFT+P --> then "run task" then click on the "Liaison du fichier compilé aux
bibliothèques SFML" task.
the entire file is as (for me):
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"suppressTaskName": true,
"tasks": [
{
"taskName": "Compilation",
"isBuildCommand": true,
"args": ["-c", "${workspaceRoot}\\main.cpp", "-IC:\\SFML-2.4.0\\include"]
},
{
"taskName": "Liaison du fichier compilé aux bibliothèques SFML",
"args": ["${workspaceRoot}\\main.o", "-o", "sfml-app.exe", "-LC:\\SFML-2.4.0\\lib", "-lsfml-graphics", "-lsfml-window", "-lsfml-system"]
}
],
"showOutput": "always"
}
well there is nothing more to say, except all it's written on official web-site:
https://code.visualstudio.com/docs/cpp/config-linux
the only stuff I needed to do is to add additional library links for the compiler, which can be done in tasks.json part:
...
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-lsfml-graphics",
"-lsfml-system",
"-lsfml-window"
],
...