1.5. Building a Complex Application from the Command Line
Problem
You wish to use your command-line tools to build an executable that depends on several static and dynamic libraries.
Solution
Start by building the static and dynamic libraries on which your application depends. Follow the instructions distributed with the libraries, if they are from a third party; otherwise, build them as described in Recipe 1.3 and Recipe 1.4.
Next, compile your application’s .cpp files into object files as described in “Building a Simple “Hello, World” Program from the Command Line. You may need to use the -I option to tell your compiler where to search for the headers needed by your application, as shown in Table 1-12.
Table 1-12. Specifying directories to search for headers
|
Toolset |
Option |
|---|---|
|
All |
-I<directory> |
Finally, use your linker to produce an executable from the collection of object files and libraries. For each library, you must either provide a full pathname or tell the linker where to search for it.
At each stage of this process, if you are using a toolset which comes with static and dynamic variants of its runtime libraries, and if your program uses at least one dynamic library, you should direct the compiler or linker to use a dynamically linked runtime library, as described in Recipe 1.23.
Table 1-13 presents commands for linking the application hellobeatles from Example 1-3. It assumes that:
The current directory is hellobeatles.
The static library libjohnpaul.lib or libjohnpaul.a ...