Linking your modules
To link your application against a library, use the -l option to qcc,
omitting the lib
prefix and any extension from the library's name.
For example, to link against libsocket, specify -l socket.
You can specify more than one -l option. The qcc configuration files might specify some libraries for you; for example, qcc usually links against libc. The description of each function in the QNX OS C Library Reference tells you which library to link against.
The QNX OS linker is a single-pass linker, so you must list all libraries after all objects (.o files) on the link line. If one library (say, lib1.a) has functions that call functions in another library (say, lib2.a), then put lib1.a before lib2.a) on the link command line.
By default, the toolchain links dynamically. We do this because of all the benefits mentioned above.
If you want to link everything statically, specify the -static option to qcc, which causes the link stage to look in the library directory only for static libraries (identified by a .a extension).
Although we generally discourage linking statically, it does have this advantage: in an environment with tight configuration management and software QA, the very same executable can be regenerated at link time and known to be complete at runtime.
To link dynamically (the default), you don't have to do anything.
qcc ... -Bdynamic -l1 -l2 -Bstatic -l3 -l4 -Bdynamic -l5
This causes libraries lib1, lib2, and lib5 to be dynamically linked (i.e., qcc links against the files lib1.so, lib2.so and lib5.so), and libraries lib3 and lib4 to be statically linked (i.e., qcc links against the files lib3.a and lib4.a).
You may see the extension .1 appended to the name of the shared object (e.g., libc.so.1). This is a version number. Use the extension .1 for your first revision, and increment the revision number if required.
You may wish to use the above mixed-mode
linking because some of the libraries you're using are
needed by only one executable or because the libraries are
small (less than 4 KB), in which case you'd be wasting memory
to use them as shared libraries. Note that shared libraries
are typically mapped in 4-KB pages and require at least
one page for the text
section and
possibly one page for the data
section.