Linking your modules








This will cause libraries lib1, lib2, and lib5 to be dynamically linked (that is, will link against the files, and, and libraries lib3 and lib4 to be statically linked (that is, will link against the files lib3.a and lib4.a).


You might want to use the above mixed-mode linking because some of the libraries you are using are needed by only one executable or because the libraries are small (less than 4 KB), in which case you are 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.

When you specify -Bstatic or -Bdynamic, all subsequent libraries are linked in the specified manner.

Creating shared objects

To create a shared object suitable for linking against:

  1. Compile the source files for the library using the -shared option to qcc.
  2. To create the library from the individual object modules, simply combine them with the linker (this is done via the qcc compiler driver as well, also using the -shared command-line option).

Make sure that all objects and static libs that are pulled into a .so are position-independent as well (that is, also compiled with -shared).

If you make a shared library that has to static-link against an existing library, you can't static-link against the .a version (because those libraries themselves aren't compiled in a position-independent manner). Instead, there's a special version of the libraries that has a capital S just before the .a extension. For example, instead of linking against libsocket.a, you link against libsocketS.a. You shouldn't static-link, but rather link against the .so shared object version.

Specifying an internal name

When you're building a shared object, you can specify the following option to qcc:

"-Wl,-h name"

(You might need the quotes to pass the option through to the linker intact, depending on the shell.)

This option sets the internal name of the shared object to name instead of to the object's pathname, so use name to access the object when dynamically linking. You might find this useful when doing cross-development (that is, from a Windows system to a BlackBerry 10 OS target).

Last modified: 2014-12-11


comments powered by Disqus