Linking math library to visual studio code GCC - c

I'm trying to link the math library to the C debugger than comes with visual studio code, GCC. I'm want to mimic what the argument -lm does when I use a makefile. To my understanding I can do this using the launch.json file shown below.
{
"version": "0.2.0",
"configurations": [
{
"name": "gcc - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": ["nums"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
I looked through the documentation https://code.visualstudio.com/docs/cpp/launch-json-reference. The closest thing I could find was "miDebuggerArgs". I tried adding the line "miDebuggerArgs": "-lm" to the "configurations" list, but it didn't work. Any advice?

You posted the launch.json file. Go to the tasks.json and add -lm to the arguments.
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/bin/${fileBasenameNoExtension}",
"-lm"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"isDefault": true,
"kind": "build"
},
"detail": "compiler: /usr/bin/gcc"
}
]
}

Related

Use gdb in vscode with -lm flag

As of https://code.visualstudio.com/docs/cpp/launch-json-reference, I can only attach to an already existing binary with vscode (in the example being a.out), but I would like to have it in a way so that I can debug without having to compile manually first (with the -lm flag). How would I go about that?
Figured it out. Instead of only using a launch.json, I also used a task.json as follows in order to build the c file first:
{
"version": "2.0.0",
"tasks": [
{
"label": "build C file",
"type": "shell",
"command": "gcc -g -o ${workspaceFolder}/sum/main ${file} -lm",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
In the launch.json, I use the task as a preLaunchTask:
{
"version": "0.2.0",
"configurations": [
{
"name": "C Debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/sum/main", // Dummy value
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"preLaunchTask": "build C file",
}
],
}
More info on tasks here: https://code.visualstudio.com/docs/editor/tasks

Value of miDebugger path is invalid in VS code while executing c program

Getting continuous error "unable to start debugging. The value of miDebuggerPath is invalid". while running a c program in VS Code
Here is launch.json file
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gcc",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe"
}
]
}
and here is tasks.json
{
"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 tried to change the path of compiler but it's not working.

MinGW Debugger in VS Code is Stuck at Building tasks. What can I do to get it back to normal? I

Earlier it used to create the .exe files whenever I hit the F5 button to debug the code. But now for some reason I am unable to get it right and I messed up with the .json files, and it keeps throwing errors.
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-Wall",
"-Wextra",
"-Wpedantic"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: C:\\MinGW\\bin\\gcc.exe"
}
]
}
This is the tasks.json file.
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"internalConsoleOptions": "openOnSessionStart",
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
This is the launch .json file.

exe. file not running in vs code

when I try to run c-code in "VS Code", it not showing output.
but exe. file is made by compiler as shown in image.
I cross checked that I add GCC,G++ in environment variable so,
mostly there is problem in config
''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''
launch.json-->
{
// 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": [
{
"name": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
task.json -->
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Go to settings -> Search for channel -> In C/C++ setting will be INSIDER -> Update to DEFAULT

I get an error saying " Could not find the task 'C/C++: g++.exe build active file'

I've tried most things on Stack Overflow including messing around with external console values, using a previous version of C/C++ extensions, changing cppbuild to shell, etc. Nothing seems to make it work. If I press debug anyway, I get an error saying the launch program '....launch.exe' does not exist.
Here is my launch.json:
{
// 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": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\msys64\\mingw64\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe"
}
]
}
Here is my task.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\msys64\\mingw64\\bin\\gcc.exe"
},
{
"label": "run make",
"type": "shell",
"command": "make"
},
{
"label": "run make test",
"type": "shell",
"command": "make test"
}
]
}
"preLaunchTask": "C/C++: g++.exe build active file" in launch.json, should be consistent with "label": "C/C++: gcc.exe build active file" in tasks.json.

Resources