C++ All-in-One For Dummies
Book image
Explore Book Buy On Amazon
Most of the Boost library works just fine by adding headers to your application code. However, a few components, such as RegEx, require a library. Before you can use a library, you must build it. After you build the library, you must add it to your application.

There are two techniques for adding the required headers and libraries to an application. The first technique is to add it to the compiler settings. The second technique is to add the settings to a specific project.

You use the first technique when you work with Boost for a large number of projects and require access to all libraries. The second technique is best when you use Boost only for specific projects and require access only to specific libraries.

The following steps show you how to perform the project-specific setup for any library, not just the RegEx library:

Use the Project wizard to create a new project.

Every application begins with a new project.

Choose Project→Build Options.

Code::Blocks displays the Project Build Options dialog box.

Select the Linker Settings tab.

You see a number of linker settings, including a Link Libraries list, which will be blank.

Click Add.

Click Add.

Code::Blocks displays the Add Library dialog box.

Click the Browse button — the button sporting the ellipses.

You see the Choose Library to Link dialog box.

Using the dialog box, navigate to thelibboost_regex-mgw47-mt-1_55.alibrary (the release version of the library), select the library, and then click OK.

The Boost library files are typically located in the Boostlib directory. When you click OK, you see a dialog box that asks whether you want to keep this as a relative path.

Relative paths specify a location using the current location as a starting point. The alternative is an absolute path, which specifies a location based on the root directory of your hard drive. In most cases, absolute paths are less likely to get broken.

Click No.

You see the absolute path for the libboost_regex-mgw47-mt-1_55.a library added to the File field of the Add Library dialog box.

Click OK.

Click OK.

After you click OK, you see the absolute path for the library added to the Linker Settings.

Click the Search Directories tab.

You see three sub-tabs: Compiler, Linker, and Resource Compiler.

Click Add in the Compiler sub-tab.

Click Add in the Compiler sub-tab.

You see an Add Directory dialog box like the one shown.

Type the location of the Boost header files in the Directory field.

As an alternative, you can click the Browse button to use a Browse for Folder dialog box to find them. The files are normally located in the Boostincludeboost-1_55 folder.

Click OK.

Click OK.

You see the search folder added to the Compiler tab as shown.

Click Add in the Linker sub-tab.

You see yet another Add Directory dialog box.

Type the location of the Boost library files in the Directory field and then click OK.

The Boost library files are typically located in the Boostlib directory. After you click OK, you see the directory added to the Linker tab.

Click OK.

The RegEx library is now ready for inclusion in your application.

About This Article

This article is from the book:

About the book author:

John Mueller has published more than 100 books on technology, data, and programming. John has a website and blog where he writes articles on technology and offers assistance alongside his published books.

Luca Massaron is a data scientist specializing in insurance and finance. A Google Developer Expert in machine learning, he has been involved in quantitative analysis and algorithms since 2000.

This article can be found in the category: