Sunny Days 12 – Compiling made easy

One of the major problems with Solaris 10 is the variety of different repositories available where you can get your additional software and libraries from. First, there’s the standard software shipped with the system. Next comes the whole bunch of (mostly outdated) stuff in /usr/sfw. In addition you can add from SunFreeware.com the packages of which are put below /usr/local. Lastly, there’s BlastWave.org living in /opt/csw once you chose to install and use it.

In case you intend to compile your own stuff, this mixture of repositories tends to become a major PITA. Not only because you have to painstakingly specify the different locations of the various components. But also because of some really braindead tools that’ll happily ignore the locations you pointed to but instead will grab the first matching library that happens to cross their path – PHP being one of them.

So, what can you do about that? On Linux you’d just modify /etc/ld.so.conf to define the order of the directories to be searched for libraries. But heck, there’s no such file on Solaris, or is it? Actually, there is. However, you can’t edit the config file directly. Instead you’ll have to use the utility crle.

Called without any option, it’ll give you an output similar to this:

-bash-3.00$ crle

Default configuration file (/var/ld/ld.config) not found
Default Library Path (ELF): /lib:/usr/lib (system default)
Trusted Directories (ELF): /lib/secure:/usr/lib/secure (system default)

Two things to notice: First, crle obviously tries to find a file named /var/ld/ld.config. Second, for the file is absent, it uses hardcoded defaults.

Dont’ bother creating /var/ld/ld.config using a text editor, it won’t work. Instead you have to use crle like this:

crle -l /lib:/usr/local/lib:/usr/lib

This will not only create the file /var/ld/ld.config but also add /usr/local/lib to the list of pathes searched. By putting that one in front of /usr/lib we make sure, that our libraries take precedence over anything that’s in Solaris’ default repository for user libraries. This can be easily verified by calling crle without any parameters again:

-bash-3.00$ crle

Default Configuration File [Version 4]: /var/ld/ld.config
Default Library Path (ELF): /lib:/usr/local/lib:/usr/lib
Trusted Directories (ELF): /lib/secure:/usr/lib/secure (Systemstandard)

But it doesn’t stop there. Maybe you’d like to add the Blastwave repository after /usr/local/lib. All you have to do is this:

crle -l /lib:/usr/local/lib:/opt/csw/lib:/usr/lib

Now you might say “Wait, won’t this duplicate the locations we already defined?”. Simple answer: No, it won’t. That’s because crle is smart enough to detect duplicate pathes and remove them from the list. To do this it first adds the list of path names we supplied, then goes through the list of the old path names and removes any duplicates from there. So in essence our new definition will always take precedence over what has been defined before. This even works with temporary re-ordering of the path definitions within a shell script you may be using to build your stuff. (Actually, you shouldn’t do this because at runtime most likely the wrong libraries will be picked by the application. Still, it’s possible to do so.)

So crle is a great tool to simplify building and running your applications. Besides the options mentioned here, there’s a lot more it can do. I suggest you experiment with the tool a bit. Start by issuing

man crle

on your Solaris console ;)

This entry was posted in Hardware, Misc. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>