[Mono-list] DllImport and modifying library search path
Alexander M. Batishchev
abatishchev at godfather.net.ru
Fri Feb 11 03:12:10 EST 2011
Hi,
Have you tried set the variable in static constructor? Or set probing
privatePath in App.config?
-----Original Message-----
From: mono-list-bounces at lists.ximian.com
[mailto:mono-list-bounces at lists.ximian.com] On Behalf Of Uli Hertlein
Sent: Friday, February 11, 2011 10:26 AM
To: mono-list
Subject: [Mono-list] DllImport and modifying library search path
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
_______________________________________________
Mono-list maillist - Mono-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list
More information about the Mono-list
mailing list