View Full Version : compiling clanLib app on linux - shared objects

10-14-2013, 07:28 PM
Hi everyone,

I'm using clanLib 3.0 on linux (ubuntu 13.04). I compiled and installed clanLib successfully and done some very simple programs to become familiar with this library, and I really like it.
But I'm generally new in c++ programming (I have expirience with php and java), what I mean is I know the language at sufficient level (and I'm learning fast :P), I know and understand OOP, some design patterns etc etc... But what I don't understand:
I see the clanLib is compiled into shared libraries (.so files). So when I put my executables on another machine and try to run it, it tells me that some shared objects are missing. As I read, the shared object is something similar to windows .dll. But under windows, clanlib for ms VS is compiled into .lib files which seem to be a static libraries (?).

So, do I need to have this clanLib shared libraries with my executable on each machine I want it to work? Or maybe there is some way to compile it with this libraries into one executable containing everything it needs to run?

What are this .so files in comparation to windows .dll's or .lib's of VS?

10-14-2013, 07:46 PM
You are correct, .so files are the Linux equivalent of .dll files under Windows.

You could copy all the .so dependency files and bundle them with your executable (similar to placing DLL files next to the exe in Windows), but in practice this is often difficult to do properly. What most binary distributions do instead is to link statically do the libraries they use. The Windows version of ClanLib is always a static library, while the Linux version currently can be built both dynamically and statically.

To link statically, you add the --static command line option to GCC when you link your executable. You may also need to add some parameter to ./configure when building ClanLib. I am not entirely sure of the details (maybe Rombust knows).

10-14-2013, 08:27 PM
I've never done it.

I've always assumed that "make" creates both the shared and static libraries

I can't check at the moment

Personally, I would recommend always linking with static.

Note, even when linking with static, we still use dlsym to dynamically load "libGL.so.1", since it depends on the installed graphics drivers.

10-14-2013, 08:41 PM
Thanks for you replies,

It all gets more clear to me now. Since I read what Judas wrote, I am looking for more information about static and dynamic linking through google. I tried compile it with -static param, and I got an error:

Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

So I tried to find something about it, without success. And it fits into what you said about the "libGL.so.1", but I don't know how to do it.
Could you explain, like to fool (:p), what do you mean by "use dlsym" and how to link this particular library dynamically, please?

10-14-2013, 08:51 PM
Try .. " -static -static-libgcc -static-libstdc++ "

But ... http://www.akkadia.org/drepper/no_static_linking.html

Googling around suggests do not static link!

However, you still should be able to do it, without "-static"
by manually linking in the compiled clanlib libraries.

With everything else (excluding clanlib) dynamic linking