vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Setting LD_LIBRARY_PATH environment variable

Open dhiraj113 opened this issue 9 years ago • 13 comments

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 avatar Apr 07 '17 22:04 dhiraj113

@dhiraj113 can you paste your entire launch.json please?

pieandcakes avatar Apr 10 '17 18:04 pieandcakes

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 avatar Apr 10 '17 19:04 dhiraj113

@dhiraj113 just want to know have you solved this or not and how?

shoutrain avatar May 15 '18 09:05 shoutrain

Have same problem with Visual Studio 2017 and open-folder feature. Any solution?

Elemental239 avatar Oct 11 '18 10:10 Elemental239

@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

pieandcakes avatar Oct 11 '18 23:10 pieandcakes

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

duzeev avatar Mar 20 '20 07:03 duzeev

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

aleksas avatar May 14 '21 12:05 aleksas

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.

CoeusK avatar Jun 29 '21 02:06 CoeusK

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"

Osyotr avatar Dec 16 '21 13:12 Osyotr

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".

callahanp avatar Dec 25 '21 14:12 callahanp

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

Rick1Chen avatar Sep 23 '22 03:09 Rick1Chen

It is still broken today version 1.90. The only solution for me was using "envFile" in launch.json, and create an environment file

incardon avatar Jul 06 '24 09:07 incardon

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

jcbastosportela avatar Jul 18 '24 11:07 jcbastosportela