Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get shared library names like ``libhello.so.0.0.1'' with scons?

I'm using the scons utility to generate shared libraries. When I write the following rule:

SharedLibrary('hello', 'hello.c')

I would get the ``libhello.so'' file.

Is there a way to get files like ``libhello.so.version'' automatically?

like image 854
Alexander Avatar asked Jun 08 '10 11:06

Alexander


3 Answers

Versioned libs have been nicely integrated into SCons 2.3.0:

version = "1.2.3"

lib = env.SharedLib(target='name', sources, SHLIBVERSION=version)

# generates in linux:
# name.so -> name.so.1
# name.so.1 -> name.so.1.2.3
# name.so.1.2.3

installed = env.InstallVersionedLib(os.path.join(INSTALPREFIX,"lib"), lib, SHLIBVERSION=version)

# generates in linux if INSTALLPREFIX = /usr/local/lib and --install_sandbox=mysandbox given:
# mysandbox/usr/local/libname.so -> name.so.1
# mysandbox/usr/local/name.so.1 -> name.so.1.2.3
# mysandbox/usr/local/name.so.1.2.3

SCons 2.3.0 still has some bugs around: a library rebuild fails since symbolic link creation relies on os.symlink which fails if the link already exists. This is already fixed in current development version. You can patch your local 2.3.0 version by prepending those lines:

try : os.remove(whatever)
except OSError : pass

Whenever os.symlink is called on those files, being 'whatever' the second parameter:

/usr/lib/scons/SCons/Tool/install.py
/usr/lib/scons/SCons/Tool/__init__.py
like image 111
vokimon Avatar answered Sep 28 '22 08:09

vokimon


You may want to use libtool to deal with shared library creation and versioning. You will unfortunately have to integrate libtool with SCons yourself as this is not built in the software. The reason, of course, being that libtool is platform specific.

As a cheap alternative, you can override env['SHLIBSUFFIX'] to something like:

Replace(SHLIBSUFFIX = '.so.$SHLIB_VERSION')

Then you can override the $SHLIB_VERSION construction variable independently per target:

SharedLibrary('hello', 'hello.c', SHLIB_VERSION = 1)
like image 30
BenG Avatar answered Sep 28 '22 09:09

BenG


There is an open bug report about the lack of soname support in SCons, along with a proposed patch from Eric S. Raymond.

Support for versioned shared libraries (soname)

This feature aims at providing better handling for shared-library generation and installation under Unixes, including proper setting of soname and rpath/loadpath.

Loosely based on the works of Richard Levitte, Eric S. Raymond has offered his code (see attachment) for integration to the SCons core routines. It has so far been tested under Linux, *BSD, and darwin, and was considerably cleaned up and debugged. It's used in production for the gpsd project already.

Still, some work has to be done. A decision has to be made about whether this feature should be offered to the user via the normal SharedLibrary() call, or a separate function like VersionedSharedLibrary().

like image 21
John Kugelman Avatar answered Sep 28 '22 08:09

John Kugelman