Compiling GAlib Using Microsoft Visual C++
GAlib is a software development library for Evolutionary Algorithms, a branch of Artificial Intelligence concerned with finding solutions to complex problems using the principles of natural evolution and selection. This page gives a brief summary of the steps required to compile the GAlib library and the provided examples using the Microsoft Visual C++ development platform.
Contents
- Prerequisites
- Step 1: Modify the Filename Extensions
- Step 2: Create a New Solution and Project
- Step 3: Import the Source and Header Files
- Step 4: Modify Filename References in the Source Code
- Step 5: Set the Project Properties
- Step 6: Build the Project
- Step 7: Add a New Project for the Example
- Step 8: Import the Example's Source Files
- Step 9: Set the Project Properties for the Example
- Step 10: Set the Project Dependencies for the Example
- Step 11: Build and Run the Example
- Linking Problems
- Links
Prerequisites
- GAlib version 2.4.7
- Available for download from the GAlib website.
- Microsoft Visual C++
- The Express edition is available to download for free from the Microsoft website. This tutorial was written for the 2005 version but it should be applicable to the current 2008 edition. It should also be applicable to the versions of Visual C++ that are shipped with the Express, Standard, and Professional versions of Microsoft Visual Studio.
Step 1: Modify the Filename Extensions
Open a command window ( > > cmd.exe) and change to the ga directory within the GAlib distribution.
Run the following command:
$ rename *.C *.cpp
Change to the examples directory and run the same command.
Step 2: Create a New Solution and Project
Open Microsoft Visual C++ and select > from the menu.
Select under the node in the list of on the left of this dialog.
Select in the templates panel on the right.
Enter a name for the project. In this example, the project name is ga.
Enter or browse to a location for the project. This example assumes the location to be in the subdirectory projects within the GAlib distribution directory e.g. C:\galib247\projects .
Enter a name for the solution e.g. vcpp2005 and check the check box.
Once you have created the solution, the top entry in the Solution Explorer should now show . The project should also be shown directly below this with three empty sub-entries: , , and .
Step 3: Import the Source and Header Files
Right-click on the node and select > in the pop-up menu. In the dialog box that opens, browse to the ga directory within the GAlib distribution on your system. Enter *.h into the text box and press Enter. This will filter non-header files out of the list. Select all the files using Ctrl+A and then click .
Right-click on the node and select > in the pop-up menu. In the dialog box that opens, browse to the ga directory within the GAlib distribution on your system. Enter *.cpp and press 'Enter' to filter non-source files out of the list. Select all the files using Ctrl+A and click .
Step 4: Modify Filename References in the Source Code
Because we renamed a number of files in step 1, we also need to replace any references to those files within the GAlib source code itself. Select from the menu and select in the combo box in the dialog that opens. For each row in the following table, replace the original text with the new text:
| Original Text | New Text |
|---|---|
| <ga/gatree.c> | <ga/gatree.cpp> |
| <ga/gaallele.c> | <ga/gaallele.cpp> |
| <ga/galist.c> | <ga/galist.cpp> |
| <ga/gatreegenome.c> | <ga/gatreegenome.cpp> |
| <ga/ga1darraygenome.c> | <ga/ga1darraygenome.cpp> |
| <ga/ga3darraygenome.c> | <ga/ga3darraygenome.cpp> |
| <ga/ga2darraygenome.c> | <ga/ga2darraygenome.cpp> |
| <ga/galistgenome.c> | <ga/galistgenome.cpp> |
The following replacements are not essential but conform to standard C++ practice:
| Original Text | New Text |
|---|---|
| <stdio.h> | <cstdio> |
| <stdlib.h> | <cstdlib> |
| <assert.h> | <cassert> |
| <limits.h> | <climits> |
| <time.h> | <ctime> |
| <math.h> | <cmath> |
| <string.h> | <cstring> |
Step 5: Set the Project Properties
Select the project in the Solution Explorer and click from the menu.
Set the active configuration to in the combo box on the top left of this dialog and set the following :
- =
- =
- = ..\..\..
- = _CRT_SECURE_NO_DEPRECATE
- =
- =
Step 6: Build the Project
The default build configuration in Visual C++ has debugging enabled. If you don't want to debug the GAlib code, select from the menu and change the configuration to in the combo box on the top left of the dialog.
Select from the menu to build the project.
Step 7: Add a New Project for the Example
GAlib provides over 20 examples and the following shows how to import one of these into a new project in the solution.
Select > from the menu. Select > in the list on the left.
Select in the list on the right.
Enter a project name. This example uses the project name ex1.
In the wizard that opens, click to skip the first page.
Check in the group and un-check the check box.
Click to close the wizard and add the project to the solution.
Step 8: Import the Example's Source Files
Right click on the node under the project node and click > .
Browse to the examples directory in the GAlib distribution and select ex1.cpp. Click .
Step 9: Set the Project Properties for the Example
Select the project node in the Solution Explorer and click from the menu.
Set the active configuration to in the combo box on the top left of this dialog and set the following property values:
- =
- =
- = ..\..\..
- =
- = _CRT_SECURE_NO_DEPRECATE
- =
- =
Step 10: Set the Project Dependencies for the Example
Select the project in the Solution Explorer. Select from the menu.
Select in the combo box at the top of the Dependencies tab page.
Check the project in the list and click .
Step 11: Build and Run the Example
Select from the menu.
Set the example project as the startup project of the solution by selecting the project node in the Solution Explorer and selecting in the menu.
To run the example, select in the menu. To run in debugging mode, select in the same menu.
Linking Problems
One reader has posted some additional comments relating to errors he experienced when linking the example executable with the library. These errors were of the form:
Error1error LNK2005: public: void __thiscall std::basic_ios >::clear(int,bool)(?clear@?$basic_ios@DU? $char_traits@D@std@@@std@@QAEXH_N@Z) already defined in ex1.objmsvcprtd.lib
The following steps solved this problem for the reader:
- In > set the runtime library type in both library and to the same value. In this example, the value Multi-threaded Debug (/MTd) was used.
- In > > > , set to MSVCRTD.lib;msvcprtd.lib.