External VS Code Compiler - c++

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"
]
}
]
}

Related

How to configure VSCode to compile C++ project with files in different directories

I'm new to C++ programming and VSCode. When I was moving from VS2019 to VSCode I just copied someones task.json and was happy. But now I'm trying to organise my code in structured project like this:
project_directory
docs
includes
header.h
src
main.cpp
functions.cpp
tests
My tasks.json looks like that:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++-11 build active file",
"command": "/usr/bin/g++-11",
"args": [
"-fdiagnostics-color=always",
"-g",
"-std=c++20",
"${fileDirname}/**.cpp",
"${fileDirname}/**.h",
"-o",
"${fileDirname}/mainExecutable"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/g++-11"
}
]
}
When all files were in the "project_directory" it compiled. But with current structure I have to add header file to every directory that contain .cpp files. And my executable file is now located in "src" directory. What should I change in "tasks.json" to make it compile?

i want my vs code to create the executables for c++ files in a separate folder and run from there

I am using vs code since a while for c++ development . But when a directory has 10 to 15 c++ files the file directory looks super messy and it's annoying to delete them once in a while . Is there a way so that by default vs code create the .out executable file in a separate folder . I am using vs code on ubuntu 20.04 lts . I am attaching details of my c++ build system for more clarity . Please help me with this .
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cpp build active file",
"command": "/bin/cpp",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /bin/cpp"
}
]
}
what to do to solve the following issue ?

Verbose mode in Visual Studio Code build C/C++ files

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
}
}
]
}

${workspaceFolder}\\*.cpp apparently not recognized as a valid path in vscode tasks.json

When pressing ctrl+shift+b in my workspace folder, I'm getting The terminal process terminated with exit code 1. That seems to mean the path is incorrect. Yet, I'm following instructions from Microsoft over here:
https://code.visualstudio.com/docs/cpp/config-mingw#_modifying-tasksjson
I also checked over stackoverflow and this should definitely work. When I replace *.cpp to main.cpp, it compiles without a problem. I have only one file right now but I will definitely have more in the future.
I am using vscode 1.44.2, g++ 9.3.0.
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "D:\\cygwin64\\bin\\g++.exe",
"args": [
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${workspaceFolder}\\BreadShopPro.exe"
],
"options": {
"cwd": "D:\\cygwin64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Did you put a space between the name of any folder in the directory? Putting a space makes the directory invalid (i.e. "My Project" will not be recognized, but "MyProject" will). Seems like that may be the issue. I've faced the same issue and this fixed mine.

How to create separate tasks for building and running c++ code in Visual Studio Code (VSCode)

I feel like this should have been very straightforward but googling leads me to various blogposts with no direct answer.
I want to have a few different build tasks:
1) Just Build with debugging on
2) Build with debugging off
3) Run the binary output file
4) Build with debugging off and run the binary output file.
{
"version": "2.0.0",
"tasks": [
{
"label": "Build with Clang and Debugging",
"type": "shell",
"command": "clang++",
"args": [
"-std=c++11",
"-stdlib=libc++",
"helloworld.cpp",
"-o",
"helloworld.out",
"--debug"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Build with Clang without Debugging",
"type": "shell",
"command": "clang++",
"args": [
"-std=c++11",
"-stdlib=libc++",
"helloworld.cpp",
"-o3",
"helloworld.out"
],
"group": {
"kind": "build",
"isDefault": false
}
}
]
}
I am not sure how to create the above tasks and run them. I tried creating a new task for building without debugging and there seems to be a syntax error. I also want to just run (by a keyword shortcut) without manually typing for instance, ./helloworld.out on the terminal.
And the "isDefault": false seems to be giving me some syntax error.
Is there a way to have all these tasks and assign a keyboard shortcut to each of them?