core icon indicating copy to clipboard operation
core copied to clipboard

Dllimport does not find libraries outside of system default (Linux)

Open furoraest opened this issue 8 years ago • 1 comments

when doing PInvoke call, like [DllImport("mylib")] private static extern int some_external_func(); the dotnet does not find library, unless in its some system default (like /usr/lib) If to explicitly state the actual library name like "libmylib.so.0.0.0" it will find it ldconfig is finding the libraries correctly, using ld.so.conf and stating custom library folder. Temporary solution was to add LD_LIBRARY_PATH to the running environment pointing to the library folder, which should not be necessary if the ldconfig lists those libraries already. If already linked library tries to use other library (outside the system default) when the dotnet program will get error: dotnet: symbol lookup error: /usr/local/lib/libmylib.so: undefined symbol: _ZN2gr6some9awesome4functionEmmPcibi Used platform: Ubuntu 18.04 and SDK 2.1 RC1 My current solution is to handload the all required libraries, using this code: [DllImport("dl")] private static extern IntPtr dlopen (string file, int mode); and then in the function somewhere before first call of the PInvoked function, call out the libraries dlopen("libmyawesomelib-x.y.z.0.so.0.0.0", RTLD_LAZY|RTLD_GLOBAL); dlopen("libmyawesomelib2-x.y.z.0.so.0.0.0", RTLD_LAZY|RTLD_GLOBAL);

furoraest avatar May 20 '18 19:05 furoraest

Issue moved to dotnet/coreclr #18599 via ZenHub

Petermarcu avatar Jun 21 '18 23:06 Petermarcu