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
C# Null Coalescing Operator Equivalent for C++
Incorrect Syntax Near the Keyword 'User'
Call C++ Function Pointer from C#
Onchange Event for HTML.Dropdownlist
How to Access Resourcedictionary in Wpf from C# Code
Mvc-Web API: 405 Method Not Allowed
Get Text Between 2 HTML Tags C#
Asp.Net MVC Using Web API to Return a Razor View
How to Get the Value of a Session Variable Inside a Static Method
Does Ef Upsert Have to Be Done Manually
How to Convert Code from C# to PHP
Capturing Count from an SQL Query
String.Format Alternative in C++
How to Join 2 or More .Wav Files Together Programmatically
Generate PDF Based on HTML Code (Itextsharp, Pdfsharp)
Why Does a Float Variable Stop Incrementing at 16777216 in C#