microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.52k stars 1.55k forks source link

[Linux] Cannot Pass Environment Variable To Debug Session #3189

Open brandon654321 opened 5 years ago

brandon654321 commented 5 years ago

Describe the bug

I am attempting to debug an application that has to link to some custom DLL's.

The application needs the proper path set in the LD_LIBRARY_PATH environment variable.

When I launch the application in debug mode, I receive the following output.

_&"warning: GDB: Failed to set controlling terminal: Operation not permitted\n" /home/myuser/git/myworkspace/bin/debug/Linux/3.10.0/x8664/myprogram: error while loading shared libraries: mySharedLib.so: cannot open shared object file: No such file or directory

The problem is simple, I just need to get the debug session to have the proper environment variable setup prior to launching my application.

In my launch.json file, I have external console set to FALSE. When I echo the LD_LIBRARY_PATH variable from this terminal it has the correct path. If I launch my program from here (non debug mode) it works fine.

I have tried the following settings in launch.json...

"args": ["${env:LD_LIBRARY_PATH}"],

"environment": [ { "name": "LD_LIBRARY_PATH", "value": "/mypath/to/lib/" } ]

"setupCommands": 
[{ 
     "description": "Additional libs",
     "text": "set env LD_LIBRARY_PATH =/mypath/to/lib/",
}],

"additionalSOLibSearchPath" : "/mypath/to/lib/"

But I continue to receive the same error where it cannot find my libs. This seems like something trivial and should work. Anyone else with this issue?

WardenGnaw commented 5 years ago

environment in the launch.json will set the environment variable before it launches the program.

Calling getenv("LD_LIBRARY_PATH") with "environment": [ { "name": "LD_LIBRARY_PATH", "value": "/mypath/to/lib/" } ] set in the launch.json and it outputs /mypath/to/lib/.

To clarify, do you want your program's environment to have LD_LIBRARY_PATH set?

brandon654321 commented 5 years ago

Yes, I needed the shell which launched the program to have the proper LD_LIBRARY_PATH set. I was able to achieve this by using the setupCommands on a different machine. The setupCommands is just some commands which are run within GDB before it launches my program to be debugged. Still not sure how/why setting environment would not correctly setup the environment variable in the new shell (I think VSCode launches a new shell every time you start a debug session, regardless of external or internal).

Anyway I got tired of messing with the settings and just added the necessary initialization modules & paths I needed into my bash.rc so everytime VSCode launches a debug session in a new shell, the new shell by default has all the proper variables set.

duzeev commented 4 years ago

https://github.com/microsoft/vscode-cpptools/issues/616

mbrunnen commented 4 years ago

https://github.com/microsoft/vscode-cpptools/issues/616

Also not solved there, just closed.

Ampaex commented 1 year ago

I'm also having this issue now.