Setting LD_LIBRARY_PATH environment variable
I am unable to set LD_LIBRARY_PATH environment variable on Ubuntu 16.04 for executable run through vscode. I am using the below launch.json configuration for setting the environment variable.
"environment": [
{
"name": "LD_LIBRARY_PATH",
"value": "<path>"
}
],
@dhiraj113 can you paste your entire launch.json please?
Below is my launch.json file
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "/home/dhiraj/opt/sst-core/bin/sst",
"args": ["/home/dhiraj/Code/SST/sst-elements/src/sst/elements/memHierarchy/tests/sdl5-1-ramulator"],
"stopAtEntry": true,
"cwd": "/home/dhiraj/Run/vscode",
"environment": [
{
"name": "LD_LIBRARY_PATH",
"value": "/home/dhiraj/Code/SST/sst-elements/external/ramulator"
}
],
"externalConsole": true,
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
},
{
"name": "C++ Attach",
"type": "cppdbg",
"request": "attach",
"program": "enter program name, for example ${workspaceRoot}/a.out",
"processId": "${command.pickProcess}",
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
}
]
}
@dhiraj113 just want to know have you solved this or not and how?
Have same problem with Visual Studio 2017 and open-folder feature. Any solution?
@Elemental239 if you enable logging, you should be able to see that we send the command to gdb using -interpreter-exec console "set env <name> <value> during the start up.
To see logging in Visual Studio 2017, go to the Command Window and enter Debug.MIDebugLog /On /OutputWindow and you'll see it all in the output window.
In VS Code it is done by adding "logging": { "engineLogging": true } in launch.json
relative path example
{
// 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": "(gdb) mtclient",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/mtclient/obj-linux/debug/mtclient",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}/mtclient",
"environment": [
{
"name": "LD_LIBRARY_PATH",
"value": "${LD_LIBRARY_PATH}:${workspaceFolder}/libbase/obj-linux/debug:${workspaceFolder}/lib1/obj-linux/debug"
}
],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
At least for debugger the only way I was able to set LD_LIBRARY_PATH was by passing it to gdb via cmake.debugConfig.setupCommands:
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Additional libs for gdb",
"text": "set environment LD_LIBRARY_PATH=${workspaceFolder}/<rel_path>:${workspaceFolder}/<other_rel_path>:$LD_LIBRARY_PATH",
"ignoreFailures": false
}
]
I have tried like this in tcsh { "name": "LD_LIBRARY_PATH", "value": "/library/path:${DUMMYNAME}" } It works with an setenv warning. You could verify this in gdb with "set env“ command.
If anyone found this while searching on how to set LD_LIBRARY_PATH for gdbserver in Visual Studio, here you go:
"preDebugCommand": "export LD_LIBRARY_PATH=/home/me/.vs/MyProject/vcpkg_installed/x64-linux/debug/lib:$LD_LIBRARY_PATH"
I found that the "environment" section of launch.json on Lubuntu 21.10 worked differently than on 21.04. In 21.04 I had LD_LIBRARY_PATH defined relative to the location of the executable. I had to change this in 21.10 to locate built shared libraries relative to the workspace folder of the project containing the executable.
The following is what I am using.
"environment": [
{
"name": "FG_ROOT",
"value": "${workspaceFolder}/../fgdata"
},
{
"name": "LD_LIBRARY_PATH",
"value": "${workspaceFolder}/../install/simgear/lib:${workspaceFolder}/../install/openscenegraph/lib"
}
I'm filing this one under "Go Figure".
This way worked after change default terminal from tcsh to bash "environment": [ { "name": "LD_LIBRARY_PATH", "value": "${LD_LIBRARY_PATH}:${workspaceFolder}/libbase/obj-linux/debug:${workspaceFolder}/lib1/obj-linux/debug" } ],
It is still broken today version 1.90. The only solution for me was using "envFile" in launch.json, and create an environment file
I think I figured it out. We should use VSCode's variables to get to the environement's variables. In other words, use ${env:<variable>}
in this case this worked for me:
"environment": [
{
"name": "LD_LIBRARY_PATH",
"value": "/my/path/:${env:LD_LIBRARY_PATH}"
}],