[Mono-list] PInvoke and library names
caster@lagash.com
caster@lagash.com
Fri, 20 Jul 2001 01:55:31 -0300
As it seems that PInvoke is one of the "hot topics", I'll contribute with
-yet another- issue:
Libraries have different naming conventions on different systems. First,
they may simply have a different name (ie. libc vs. msvcrt). Second, each
operating system has its own rules for decorating dynamic libraries
(ie. "lib" before library name in most unixes, trailing ".dll" in windows,
trailing ".so" in linux/solaris).
When just dealing with libraries with the same name but different
"decoration", we could set a couple of rules such as:
.The DllImport clause receives the module name without any decoration:
ej: "pthread"
.On Linux systems, the name is converted to "libpthread.so"
.On AIX systems (just another sample), it would be something
like "libpthread.sh"
.On Windows systems, the resulting name would be "pthread.dll"
I'm not sure whether the MS implementation actually requires the ".dll" in
the module name. If so, we can assume that library names always end with
".dll" and replace it using the proper convention for the current
platform. This way we would still be .NET compatible while supporting
multiplatform-pinvoke. (yes, I know...it doesn't look "great"...)
We still have to deal with libraries that have completely different names
on different platforms. In that cases, we could use a custom attribute
that overrides the default library name for a given platform. That way,
the runtime would use the default library specified in the DllImport
declaration unless it finds the custom attribute that matches the
underlying platform.
Any comments?
Caster.