I have a shim library (shared, C++) which calls functions in another shared library (libexif) and presents a simple interface to C# for Platform Invoke calls. (That is, a C# program uses PInvoke to call my custom shared library which in turn calls another shared library.)
In Windows, my custom shared library links to the shared library when my custom library links and when the C# application executes, all symbols are resolved.
On Linux, linking my shared library does not link the other shared library. With a C++ driver, I specify the other library when the application is linked and at that time, all symbols are resolved. However, when I try to call my shared library from a C# program (compiled using mono) symbols in the other shared library are not resolved. I've tried using the MONO_PATH variable to specify the other library but it seems not to make a difference. I've also tried specifying the unresolved function in a DLLimport statement, but that seems not to help either.
How can I specify a shared library that is not directly called by C# code so that mono/cli finds it at run time?
I use the following commands to build the shared library:
g++ -fPIC -g -c -Wall libexif-wrapper.cpp
g++ -shared -Wl,-soname,libexif-wrapper.so.1 -o libexif-wrapper.so.1.0.1 libexif-wrapper.o -lc
ar rcs libexif-wrapper.a libexif-wrapper.so.1
And the following command line to compile my C# driver:
mcs -unsafe -define:LINUX Test-libexif-wrapper.cs
On execution I get an error that a symbol used by my shared library is not found:
/usr/bin/cli: symbol lookup error: ../../../C/libexif-wrapper/libexif-wrapper/libexif-wrapper.so.1: undefined symbol: exif_data_new_from_file
(libexif-wrapper is my shared library which serves as a shim between the C# application and libexif.)
I have not been able to figure out how to solve this. Any suggestions would be appreciated.
edit: To answer the question:
Are you sure that the unmanaged libexif-wrapper can be found in the LD_LIBRARY_PATH environment variable?
In fact it is not. I have crafted the path in the DLLImport to point directly to it instead. The run time finds it because it reports the path to it in the error message above. Further the missing symbol is not called by the C# program but rather one of the functions in my shared library calls the function that is then not found. (thanks - hank)