1.4. Building a Dynamic Library from the Command Line
Problem
You wish to use your command-line tools to build a dynamic library from a collection of C++ source files, such as those listed in Example 1-2.
Solution
Follow these steps:
Use your compiler to compile the source files into object files. If you’re using Windows, use the -D option to define any macros necessary to ensure that your dynamic library’s symbols will be exported. For example, to build the dynamic library in Example 1-2, you need to define the macro
GEORGERINGO_DLL. If you’re building a third-party library, the installation instructions should tell you what macros to define.Use your linker to create a dynamic library from the object files created in step 1.
Tip
If your dynamic library depends on other libraries, you’ll need to tell the compiler where to search for the library headers, and to tell the linker the names of the other libraries and where to find them. This is discussed in detail in Recipe 1.5.
The basic commands for performing the first step are given Table 1-8; you’ll need to modify the names of the input and output files appropriately. The commands for performing the second step are given in Table 1-11. If you’re using a toolset that comes with static and dynamic variants of its runtime libraries, direct the compiler and linker to use a dynamically linked runtime, as described in Recipe 1.23.
Table 1-11. Commands for creating the dynamic library libgeorgeringo.so, libgeorgeringo.dll, or libgeorgeringo.dylib ...