Skip to content

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

@copygirl

Description

@copygirl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions