[Mono-list] P/Invoke question...
Jonathan Pryor
jonpryor@vt.edu
Mon, 25 Oct 2004 21:46:27 -0400
On Mon, 2004-10-25 at 19:32, Tom Shelton wrote:
> Ok... I have a bit of simple c++ code that is currently residing in a WIN32
> dll. This code is called by a custom data provider for a proprietary
> database (this already works on win32, we're just trying to port the
> provider over to mono). I have very little experience in actually creating
> a shared library and getting it working on Linux. I have followed a couple
> of tutorials on line and so far, no luck. The code compiled just fine with
> g++, but I can't seem to install it correctly - since Mono never seems to be
> able to find it. Can someone point me to a good resource/tutorial on how to
> compile/install a shared object file under red hat? What do I have to do
> after that so that mono can find it?
You seem to have compiling figured out, but the summary is this:
g++ -shared -o libMYLIB.so -fpic MYFILES.cpp
The problem you seem to be having is with getting apps to find your new
library (libMYLIB.so).
See the dlopen(3), ld.so(8), and ldconfig(8) man pages for details. The
summary is that your library needs to be located in one of:
1. The LD_LIBRARY_PATH environment variable (':'-delimited,
just like $PATH).
2. One of the directories listed in /etc/ld.so.conf. You must
run ldconfig(8) after modifying this file.
3. The /lib directory, and /usr/lib.
Libraries are searched in the above order, and the first directory
containing libMYLIB.so is used.
This generally means that you *shouldn't* rely on LD_LIBRARY_PATH except
in development, as *anyone* can add a trojaned library, thus breaking
your app.
You should also consider versioning your libraries. Ulrich Drepper has
an excellent guide covering more than you'd ever want to know about
versioning and shared libraries, available at:
http://people.redhat.com/drepper/dsohowto.pdf
- Jon