Linking shared libraries: overcoming runtime errors

Say you’re developing a program in C++ and you need to use some exotic library called libAAA.
You have been able to download the sources and build the package ( by adding -I/path/to/the/library/include to the compilation options, for example) and linking it ( by adding something like -L/path/to/the/library/lib -lAAA to the linker options, for example).

But running the program raises an error:
./program_a: error while loading shared libraries: cannot open shared object file: No such file or directory

This is due to the fact that although you have informed the compiler and the linker about the location of your libAAA files, the system cannot find them at runtime. In fact, the program_a would call a dynamic linker that searches for shared libraries in the system. It, however, searches only in default locations where libraries are commonly installed (such as /usr/lib).

You can check the dynamic libraries by invoking ldd command on the executable:
>>ldd program_a => (0xb7f48000) => /usr/lib/ (0xb7836000) => not found => /usr/lib/ (0xb76c4000)
/lib/ (0xb7f49000)

Here it is clearly seen that the linker cannot find the library. A remedy is to add the custom library path to the LD_LIBRARY_PATH environment variable (this example is for bash shell):
>>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/the/library/lib

Now the library can be located at runtime:
>>ldd program_a => (0xb7f48000) => /usr/lib/ (0xb7836000) => /path/to/the/library/lib/ (0xb77da000) => /usr/lib/ (0xb76c4000)
/lib/ (0xb7f49000)

Another option is to do a manual system-wide install by copying the library to /usr/lib, for example, or modifying the dynamic linker look-up path (in file /etc/ Naturally such problems should not appear if the library is well-built so that make install will do a system-wide installation automatically.

More information can be found in here for instance.

Duplex printing for HP Color printers in Ubuntu

In office we have this fast HP Color LaserJet CP3505 printer, that should be able to print on both sides. I installed the driver using some GUI (system-config-printer I think) and everything worked like a charm, except the duplex printing. Trying to enable duplex printing in kprinter, for example, resulted an error “Some options selected are in conflict” as the Duplex Unit was not installed.

The printer setup can be changed (as instructed in this thread) in the CUPS HTML interface, accessible via any browser:


1) Choose Manage Printers and Set Printer Options of the printer at hand.

2) In Options Installed change radio button to Duplex Unit : Installed.

3) Click Set Printer Options.
You may be asked for a user name and password. Type in your local login user name and password. Sometimes, as in my case, you may need to input root and the superuser password.

Presumably the same configuration can be done in the GUIs as well, for example:
sudo system-config-printer and tick Duplex Unit in Installable Options tab. (In KDE use kdesu instead of sudo.)