2.7. Creating and using shared libraries

Often for a Linux application you will want to create a dynamic shared library that can be linked with a variety of applications.

Building a shared library with RVCT

Compiler Options

When building dynamic shared libraries, all of the library code must be compiled and linked to be position-independent. To do this, use the --apcs /fpic compiler switch.

Linker Options

armlink supports the creation of dynamic shared libraries; however this requires some additional options.

‑‑shared

This instructs the linker to create a dynamic shared library and not a static library

‑‑soname <name>

This specifies the SONAME (shared object name) for the library

‑‑fpic

This enables you to link position-independent code (compiled with --apcs /fpic)

For example, to link libfunc.o and asmfunc.o into a dynamic shared library libdynamic.so, you can use the following linker command line:

armlink --sysv --fpic --shared --soname libdynamic.so -o libdynamic.so libfunc.o asmfunc.o libc.so.6

Using shared libraries in your application

Shared libraries can be used with armlink in the same way as normal libraries by specifying them on the linker command line. References to the shared library will be added to the image and resolved to the library by the dynamic loader at runtime.

Note that the order in which references are resolved is the order in which libraries are specified on the command line. This is also the order in which the dependencies will be resolved by the dynamic linker. In RVCT 3.0 SP1 you can specify the runtime location of libraries using the ‑‑rpath linker option.

Copyright © 2005-2006. All rights reserved.DAI0150B
Non-Confidential