tags:

views:

145

answers:

2

Hi,

I'm working on a plain X11 app. By default, my app only requires libX11.so and the standard gcc C and math libs. My app has also support for extensions like Xfixes and Xrender and the ALSA sound system. But this feature shall be made optional, i.e. if Xfixes/Xrender/ALSA is installed on the host system, my app will offer extended functionality. If Xfixes or Xrender or ALSA is not there, my app will still run but some functionality will not be available.

To achieve this behaviour, I'm not linking dynamically against -lXfixes, -lXrender and -lasound. Instead, I'm opening these libraries manually using dlopen(). By doing it this way, I can be sure that my app won't fail in case one of these optional components is not present.

Now to my question: What library names should I use when calling dlopen()? I've seen that these differ from distro to distro. For example, on openSUSE 11, they're named the following:

libXfixes.so libXrender.so libasound.so

On Ubuntu, however, the names have a version number attached, like this:

libXfixes.so.3 libXrender.so.1 libasound.so.2

So trying to open "libXfixes.so" would fail on Ubuntu, although the lib is obviously there. It just has a version number attached. So how should my app handle this? Should I let my app scan /usr/lib/ first manually to see which libs we have and then choose an appropriate one? Or does anyone have a better idea?

Thanks guys,

Andy

A: 

From what I have learned, you just dlopen() (for example) "libXfixes.so", which is most likely a symlink to the newest file "libXfixes.so.3" anyways, in a similar fashion to this one:

$ file /usr/lib/libalpm.so
/usr/lib/libalpm.so: symbolic link to `libalpm.so.4.0.3'

A quick overview of my "/usr/lib/" shows, that almost EVERY library in there is symlinked to it's newest ".X" numbered file, and I'm sure that's how it's done on other distribtuions, too.

Only if you need a specific version of the library, you explicitly name the version "libXfixes.so.2" for example.

LukeN
A: 

You should dlopen using the library's SONAME. You can see that by using readelf -d [libname].

For example, on one of my Fedora Linux machines the SONAME of the C library is libc.so.6.

The symlinks from the .so names to the .so.6 names are not guaranteed. Those symlinks are only needed for compiling software and are usually not installed on systems without the development packages.

You would not want to end up loading a version with a different number anyway, because the number changes indicate major API differences.

Zan Lynx