LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 03-13-2004, 05:36 AM   #1
sikil_nuru
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
correct?

(Im a Cpp-programmer with SuSe 9.0 )

// Alex
 
Old 03-15-2004, 02:09 PM   #2
cjp
Member
 
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:
Code:
class myclass : public baseclass
{
    //Real C++ stuff
}

extern "C"
{

baseclass *createObject()
{
  return new myclass;
}

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

Rep: Reputation: 31
I recently wrote the original version of this wiki page:
http://wiki.linuxquestions.org/wiki/...ands_and_Files

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
Code:
g++ -o my_app main.o -l foo
where foo represents the lib named libfoo.so (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:
Code:
g++ -o my_app main.o -l/usr/local/lib/libbar.so
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:
Code:
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 gnu.g++.help newsgroup for that. Here's a link to the google archives:
http://groups.google.com/groups?hl=e...u.g%2B%2B.help
 
Old 03-16-2004, 07:51 AM   #4
cjp
Member
 
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 "libmikmod.so", minus "lib" and minus ".so".
 
  


Reply


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


All times are GMT -5. The time now is 02:55 AM.

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