Linux Dynamicly Linked Libraries
Hello! I was wondering what the counterpart for Windows DLLs is
under Linux, isn't it .SO or something? I know how to use DLLs under
Windows, but how do i use .SOs under Linux/other *NIX-systems?
Ive also heard that you can't place class-instances in .SOs, is that
(Im a Cpp-programmer with SuSe 9.0 )
.so files are similar to .dll files in windows, yes. What do you want to do with them? You can decide to link to them at compile-time (actually, the linking step of course): just add -l options to the compile command (see man gcc). If you want to choose a .so file at run-time (e.g. a plugin that is selected by the user) then you can use dlopen (see man 3 dlopen).
I'm not sure how one should create .so files (I'm sure that google will find the answer). It was easy for me because I already knew things about automake, and automake has some features to set up the compilation of complex projects including the creation of .so files.
I did some things with C++ and dlopen, and I did have some problem. You must know that C++ does some weird things with the symbol names in order to make all the fancy C++ stuff work, but dlopen assumes C-style symbols. You can use "extern "C"" to force C-style symbols for some part of the .so file. For example:
I recently wrote the original version of this wiki page:
Maybe it'll help.
To make use of .so's in your C++ code, just #include the header, and in your makefile
(or jamfile, or whatever ant uses -- depending on the build tool you're using) in your
makefile, for the linker arguments, just use
You don't have to put the -lfoo at the end of the command line, that's just the way it's done
commonly. You could also specify the whole path
if you had to:
-l, -L, -I.
Some libs even come with their own little utility to help you put the right g++ compile and
linker args in. For example, SDL comes with sdl-config. Example:
Don't know about the "class instances" question though. You might try
the gnu.g++.help newsgroup for that. Here's a link to the google archives:
The dlopen stuff & creating your own .so files are advanced programming stuff. If you're just a beginner and you just want to use one of these interesting libraries in /lib or /usr/lib, then all you have to do is include the include file and link with the .so file. For example if you want to use libmikmod for a mod player, then you should include mikmod.h and compile with
gcc -o myapp myapp.c -lmikmod
mikmod is the name of the file "libmikmod.so", minus "lib" and minus ".so".
|All times are GMT -5. The time now is 07:25 AM.|