microsoft / microsoft/vscode-mono-debug

Setting environment variable (LD_LIBRARY_PATH) for mono, rather than the program run

Open
#84 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
180
Forks
182
Avg merge
1d 8h
Merged PRs (30d)
1

Description

I'm helping out with an indie game which is built on .NET 4.6.1 and is trying its best to support Linux. Recently I found out that native libraries that were available for different architectures, and therefore stored in two different folders Lib32 and Lib64, were not able to be loaded from these paths.

In #monovm on the DotNetEvolution Discord I was recommended to use LD_LIBRARY_PATH to specify which of the folders to load libraries from. This works well when I change the game's launch script:

if [ $(uname -m) == 'x86_64' ]; then ARCH=64; else ARCH=32; fi
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/share/<game>/Lib$ARCH
exec /usr/bin/mono /usr/share/<game>/<executable>.exe

However, when trying to do something similar in the launch.json, the game still fails to find the library.

{
  "version": "0.2.0",
  "configurations": [{
    "name": "Launch Client (Mono)",
    "type": "mono",
    "request": "launch",
    "preLaunchTask": "build",
    "program": "${workspaceRoot}/bin/Debug/<executable>.exe",
    "cwd": "${workspaceRoot}/bin/Debug",
    "env": { "LD_LIBRARY_PATH": "${env:LD_LIBRARY_PATH}:${workspaceRoot}/bin/Debug/lib64" }
  }]
}

I can confirm using Environment.GetEnvironmentVariable that the variable has been set correctly, but it appears that this environment variable is only set in the context of the program itself, rather than the mono binary, which (from my understanding) in charge of loading native libraries.

Is it possible to pass environment variables to the mono executable itself when debugging?

(Note: In the released game, the library folder is called "Lib64", while when debugging from source, it's "lib64", so in case you noticed that, it's not actually a typo, just a bit of an odd decision from the core developers who develop on Windows.)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the launch.json configuration and trace how the mono debug adapter starts the mono executable versus the debugged program. Reproduce the issue using the supplied LD_LIBRARY_PATH configuration and compare it with the shell launch script; done means native libraries load successfully when debugging on Linux.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.