QEF home page
9. Library Naming and Mapping in QEF

In this section we examine library naming and mapping, the libs program, and the qvrs program's role w.r.t. libraries.


Table of Contents
Previous Page
Next Page

The command that built etoc was:

+ cc -o etoc etoc.o -L/p/qtree/9.1/linux2_0i/lib -ldt \
	/p/qtree/9.1/linux2_0i/qdev/lib/libl.a

Looking at the qeffile again:

% cats qeffile
set _F_qyacc[ctoey.y] -h -yctoe
set _F_qlex[ctoel.l] -yctoe
addpath InclPath @SrcPath -s @QTREE/include
addpath LibPath -s @QTREE/lib
set Suffixes -std 1

Begin

program ctoe.c ctoey.y ctoel.l
commands @argv

there does not appear to be any specification of the libraries.

The LIBS line The libraries for a program can be specified in the qeffile, but they are usually named in the program's source, as in:
% cats etocl.l | sed 5q
%{
/*^ ^{qlex} && ^{Rccprg}
 * LIBS:        -ldt -ll -lsocket
 * Modules:
 */

The line "/*^ ..." is a com line. The program com finds this line, replaces the ^ sequences and executes the command line as in:

% com etoc.l  # searches the SrcPath for etoc.l
+ qlex /p/cook/s3.4/ctoe/etoc.l && cc -o etoc -I. \
        -I/g/dt/cook/work/ctoe -I/p/cook/s3.4/ctoe \
        -I/p/qtree/9.1/linux2_0i/include etoc.c \
        -L/p/qtree/9.1/linux2_0i/lib -ldt
        /p/qtree/9.1/linux2_0i/lib/libl.a

Both qef and com determine the libraries to be linked with a program by retrieving associated "LIBS" line and transforming that line into --L and --l flags. The "LIBS" line is usually stored in the main() source file for the program, but it could be specified in a qvrs file or another file.

That line is transformed by applying mappings specified by qvrs variables LibMap[-l...], typically used to deal with variations of library names or non-existence of the library. The resulting list is then converted to real files by searching the directories named by the qvrs variable LibPath and applying the library naming mechanism, again expressed in qvrs variables. Finally, if shared libraries are to be used, the list is converted into --L, --l..., and static library path names.

libs: Library Search and Mapping Information To illustrate the stages, we'll use the program libs.
% libs -r etoc.l  # retrieve the raw LIBS line
-ldt -ll -lsocket

% libs -m etoc.l  # show libs after mapping
-ldt -ll	# -lsocket mapped to NULL

% libs -e etoc.l  # show libraries after file expansion
/p/qtree/9.1/linux2_0i/lib/libdt.so.9.1.1 \
    /p/qtree/9.1/linux2_0i/lib/libl.a

% libs -c etoc.l  # show cc arguments
-ldt /p/qtree/9.1/linux2_0i/lib/libl.a

% libs -a etoc.l  # show them all
raw (-r):       -ldt -ll -lsocket
mapped (-m):    -ldt -ll
expanded (-e):  /p/qtree/9.1/linux2_0i/lib/libdt.so.9.1.1 \
                /p/qtree/9.1/linux2_0i/lib/libl.a
cc args (-c):   -ldt /p/qtree/9.1/linux2_0i/lib/libl.a

Complicated? You bet. The objective of the library naming and mapping mechanism is to allow the use of simple symbolic names for the libraries, yet provide the ability to deal with diverse systems with imaginative naming and organizations.

To help the user prepare and test the "LIBS" line, there is a lot of documentation, a qvrs --l flag that outputs the significant variables, and the program libs. libs has a --X flag that explains the significant qvrs variables.

% libs -X  # produce brief descriptions of libs variables
Explanation of library mapping

qvrs Name       Form of value      Description
------------    -------------      -----------
LibPath         <directory> ...    lib search directories
LIBS[echo.c]    <-l-term> ...      libs line for echo.c
ExtraLibs       <-l-term> ...      extra libraries for
						all progs
LibMatch        lib%.so/sv lib%.a ... lib name prototypes
LibMap[-leg]    -l                 map -leg1 to nothing
LibSuffix       a                  normal library suffix
					(not used by libs)
LibMap[-leg]    -leg -leg2         map -leg -leg2
Library[-leg]   <pathname>         specifies file for -leg
LibStatic[*]    <pattern> ...      progs not to use dynamic 
					libs
LibStatic[-leg] <pattern> ...      progs not to use solib 
					 -leg
UpperCaseDepsSearches 0 or 1       search for upper case 
					names as well

To get a listing the current settings for the above use:

        qvrs -l
Following the above suggestion:
% qvrs -l  # list the variables used in lib mapping
LibPath         /p/qtree/9.1/linux2_0i/lib
CcLibDirs       /usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3
			/lib /usr/lib
LibMatch        lib%.so/sv lib%.a
UpperCaseDepsSearches # not set
LibStatic[*]    # not set
LIBS[*]         # not set
ExtraLibs       # not set
ObscuredLibs    # not set
LibMap[-lsocket] -l
LibMap[-lsymlink] -l
LibSuffix       a

Note that each of the qvrs variables are described in the x-qvrs database, as in:
% x-qvrs ObscuredLibs
ObscuredLibs(x-qvrs)  list of obscured libraries

ObscuredLibs should list the -llib symbols that do not refer
to files, but rather are special symbols to the loader, such
as -lXt on vms posix.

ObscuredLibs is usually specified in the <sysvrs>.vrs file.

See also:	libs _Libs_() *lib-macros(x-qefpp)

cook19.qh - 1.22 - 03/10/24 QEF home page Table of Contents Previous Page Next Page