When using the armadillo
C++ library I need to compile with g++
flag -larmadillo
to link the run-time armadillo library. If not, I get many undefined reference errors.
However when I want to debug with gdb
, I still get these undefined references. How can I get gdb
to use a linked library without errors? Or otherwise, how can I compile in such a way that gdb
(or any other debugger) will work?
I am using VS Code. my: tasks.json, launch.json
For me it worked when I changed the type to "type": "shell",
in the tasks.json file. This is the settings I used for the basic example in Armadillo documentation.
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-ggdb",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-std=c++11",
"-O2",
"-larmadillo"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/g++"
}
]
}
and
launch.json
{
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "${defaultBuildTask}",
}
]
}