Linker Options


Linker Options

Linker options are set in the AUXLIBS variable. After Postfix has compiled the object files, it links them together with required libraries into executable files. The standard location for system libraries is /usr/lib. To tell the linker to search additional directo- ries for libraries, use the -L option:

AUXLIBS='-L/usr/local/lib'

You must also tell the linker which specific libraries to link in. The -l option is used to name specific libraries. The library files must be in a standard location or a direc- tory indicated with the -L option. Library archive files are named starting with lib, followed by their name, followed by the extension, which is normally .a for static libraries and .so or .sl for shared objects or shared libraries. When you use the -l option, you leave off the initial lib and the extension of the library file. To link with the MySQL client library for example, where the library file is called libmysqlclient.a, the -l option is specified as follows:

AUXLIBS='-L/usr/local/lib -lmysqlclient'

Most linkers choose runtime or dynamic libraries over the static versions. Runtime libraries are linked when a program is running rather than during compilation. At compile time, the linker adds information so the program can find the libraries when it is executed. If you always install all of your dynamic libraries in a standard loca- tion such as /usr/lib, your system won’t have any trouble finding the libraries at runti me. However, some external packages install libraries in nonstandard directo- ries such that they cannot be found at runtime. Different systems use different con- ventions for locating dynamic libraries using fixed path information and environment variables. Be sure to configure your system to be able to find your dynamic libraries or make sure that the libraries are installed in your system’s stan- dard directories. Another option is to provide the actual path to specific libraries when you build your programs.

The linker uses an argument to include directories in a runtime search path for dynamic libraries. The argument differs depending on your linker and platform. The GNU linker (Linux, FreeBSD) uses -rpath , as does IRIX. Solaris, on the other hand uses -R , and HP-UX uses +b . Consult the manpage for your linker, ld(1) , to see which argument you should use to set the runtime library search path.

Using the SSL library as an example, if your libssl.so file is located in /usr/local/lib and you are building Postfix on FreeBSD or another system that uses rpath , define AUXLIBS as follows:

AUXLIBS='-L/usr/local/lib -rpath/usr/local/lib -lssl'

When linking Postfix with external libraries, if you have multiple versions of the libraries installed, it is very important to make sure that you link Postfix with the ver- sion you need. Also, make sure that the library version you link to corresponds to the correct version of the header files you include. Version mismatch problems are often the source of compiler errors. Sometimes the compiler does not complain, in which case your build may succeed, but you’re likely to find unusual errors from Postfix at runtime that can be tricky to track down.

gcc and Unrecognized Linker Options

Some versions of gcc do not understand all of the linker options you might use, and generate errors when compiling. The -rpath option is a common one. The compiler generates an error like gcc: unrecognized option '-rpath' . Since this option is really meant for the linker and gcc doesn’t really have to recognize it, there is an easy workaround. The gcc compiler uses the -Wl, argument to indicate that certain options should be passed to the linker and otherwise ignored. In this case, when you specify the -rpath option, do it with -Wl:

AUXLIBS='-L/usr/local/lib -Wl,-rpath,/usr/local/lib -lssl'
See the gcc(1) manpage for more information.

results matching ""

    No results matching ""