Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-13-2004, 05:36 AM   #1
LQ Newbie
Registered: Jun 2003
Location: Sweden
Distribution: SuSe 9.0
Posts: 13

Rep: Reputation: 0
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 )

// Alex
Old 03-15-2004, 02:09 PM   #2
Registered: Dec 2003
Location: the Netherlands
Distribution: SuSE 9.0
Posts: 54

Rep: Reputation: 15
.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:
class myclass : public baseclass
    //Real C++ stuff

extern "C"

baseclass *createObject()
  return new myclass;

Old 03-15-2004, 02:35 PM   #3
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 32
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
g++ -o my_app main.o -l foo
where foo represents the lib named (the space between -l and foo is optional).
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:
g++ -o my_app main.o -l/usr/local/lib/
See the man page for g++ for details on the most common args you'll be using:
-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:
g++ -o my_sdl_GL_app main.o Spaceship.o -lglut -lGLU -lGL  `sdl-config --libs`

Don't know about the "class instances" question though. You might try
the newsgroup for that. Here's a link to the google archives:
Old 03-16-2004, 07:51 AM   #4
Registered: Dec 2003
Location: the Netherlands
Distribution: SuSE 9.0
Posts: 54

Rep: Reputation: 15
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 "", minus "lib" and minus ".so".


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
linked lists in linux kernel how they works? cranium2004 Programming 3 03-05-2005 03:27 PM
How to see which shared libraries are linked to a program zsjoska Linux - Newbie 2 11-19-2004 01:45 PM
Getting the network device name dynamicly? predator.hawk Slackware 0 11-12-2004 11:27 PM
Winxp linked to Linux Linked to home network OverboardKiller Linux - Networking 2 06-09-2003 09:59 AM
Obtaining and IP address dynamicly getatmefosho Linux - Networking 3 12-10-2002 07:48 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration