Solaris Runtime Linker Fun

Most of the last week at work has been spent trying to coerce my way around the Solaris runtime linker (ld.so.1). The original task is to install a bunch of stuff like OpenSSL, PostgreSQL and Perl into a directory structure ($prefix) on the box. But where the task involves shared libraries, things get tricky…

Compiling and installing the shared library itself is easy. Compiling and installing a dependency on that shared library is just as simple. You have to specify that the include files and libraries are in the right place. You have to do this to get the program to compile, so it gets done anyway, usually by supplying CFLAGS=-I$prefix/include and LDFLAGS=-L$prefix/lib.

Where it starts to get hard is when you run the program afterwards. Because under Solaris, the program doesn’t remember where it found the shared library. So it goes off hunting in a number places, none of which are the ones you want, and then gives up.

The answer is to add in -R$prefix/lib to LDFLAGS. That records the correct place for the shared libraries in the program, and then everything works as expected.

Needless to say, this is exactly what Linux does by default.

Anyway, the end result is that I’ve spent far longer inside the Solaris Linker and Libraries Guide than I really care for. But I do have some working code.

Oh, I almost forgot the most irritating thing that happened during all this: teaching Perl to not look in /usr/local for includes and libraries. There were a few things in there (e.g. gdbm) that I didn’t want to link Perl to because they wouldn’t be on the target machine. But teaching Perl to exclude stuff from its Configure routine is byzantine to say the least. I ended up having to patch the solaris_2.sh hints file, which is (to say the very least) a bit sucky.

Here’s hoping next week will be looking up a bit.

Comments are Closed