Linux, Mono, Shared Libs and Unresolved Symbols

Linux, Mono, shared libs and unresolved symbols

You should specify the dependency when you link the wrapper library like

g++ -shared -Wl,-soname,libexif-wrapper.so.1 -o libexif-wrapper.so.1.0.1 libexif-wrapper.o -lc -lexif

When you do that the dynamic linker knows that libexif-wrapper depends on libexif and it can resolve the symbols on load.

undefined symbol in Mono p/invoke using misbehaving shared C library

Found a good general solution, exemplified in the code below:

  class MainClass
{
//Constants from /usr/include/bits/dlfcn.h
private const int RTLD_LAZY = 0x00001; //Only resolve symbols as needed
private const int RTLD_GLOBAL = 0x00100; //Make symbols available to libraries loaded later

[DllImport("dl")]
private static extern IntPtr dlopen (string file, int mode);

[DllImport("a")]
private static extern void f ();

public static void Main (string[] args)
{
//Load libb. RTLD_LAZY could be replaced with RTLD_NOW, but
//RTLD_GLOBAL is essential
dlopen("libb.so", RTLD_LAZY|RTLD_GLOBAL);

//Call f(), no unresolved symbol problem!
f();
}
}

Mono p/invoke giving 'undefined symbol __dso_handle'

Never mind! I figured it out. Turns out, ld is not a good way to package and link a shared library.

Instead of the ld command, i used:

g++ -shared obj/*.o -o 39dll-4-linux.so

It works like a charm!



Related Topics



Leave a reply



Submit