1.12. Building a Dynamic Library with an IDE
Problem
You wish to use your IDE to build a dynamic library from a collection of C++ source files, such as those listed in Example 1-2.
Solution
The basic outline is as follows:
Create a new project and specify that you wish to build a dynamic library rather than static library or an executable.
Choose a build configuration (e.g., debug versus release, single-threaded versus multithreaded).
Specify the name of your library and the directory where it should be created.
Add your source files to the project.
On Windows, define any macros necessary to ensure that your dynamic library’s symbols will be exported using
_ _declspec(dllexport).If necessary, specify one or more directories where the compiler should search for included headers. See Recipe 1.13.
Build the project.
As with Recipe 1.11, the steps in this outline vary somewhat depending on the IDE. The second step is covered in detail in Recipe 1.21, Recipe 1.22, and Recipe 1.23. For now, you should use default settings wherever possible.
For example, here’s how to build a dynamic library from the source code in Example 1-2 using the Visual C++ IDE.
Select New→ Project from the File menu, select Visual C++[10] in the left pane, select Win32 Console Application and enter libgeorgeringo as your project’s name. From the Win32 Application Wizard go to Application Settings, select DLL and Empty Project, and press Finish. You should now have an empty project with two build configurations, Debug and ...