[Mono-list] DllImport and modifying library search path
Uli Hertlein
uli at xdt.com.au
Fri Feb 11 02:26:17 EST 2011
Hi guys,
I'm trying to come up with a way to transparently pick up the correct OS and CPU dependent
.dll/.so/.dylib from within my application.
Assume I have the following directory structure:
Linux32/libSdk.so
Linux64/libSdk.so
MacOsX32/libSdk.dylib
MacOsX64/libSdk.dylib
Win32/Sdk.dll
Win64/Sdk.dll
The DllImport only specifies the 'base' library name, i.e.
[DllImport("Sdk", EntryPoint="foo")]
At runtime I assemble the directory based on Environment.Is64BitProcess and
Environment.OSVersion.Platform to end up with e.g. "Linux64" or "Win64".
Now, to pickup the correct shared library I thought I'd prefix the the respective search path
(LD_LIBRARY_PATH on Linux, DYLD_LIBRARY_PATH on OS X, and PATH on Windows) with this directory.
This is then set using 'Environment.SetEnvironmentVariable("LD_LIBRARY_PATH", dllSearchPath)'
On Windows/CLR this works fine, but on Mono (Linux and Windows, mono-2.10 preview) it doesn't.
I've noticed (with MONO_LOG_LEVEL=debug) that Mono is trying to lookup the DllImport before my main
even runs, as opposed to when the call to the lib is actually made.
So I am wondering if
- Mono is caching that first lookup (which fails, because the search path isn't set properly)
or
- Mono makes a copy of the search path and hence doesn't notice later changes to the environment
variable
Or something else? Any ideas?
Cheers,
/uli
--
Ulrich Hertlein
Research and Development mailto:uli at xdt.com.au
XDT Pty Ltd http://www.xdt.com.au
More information about the Mono-list
mailing list