基本配备
- GAlib version 2.4.7
- 到这里下载。GAlib website
- Microsoft Visual C++
- Visual C++ 2005 或 2008。到这里下载。Microsoft website
Step 1: 修改文件后缀
运行命令行提示符(> > cmd.exe) ,进入GAlib 解压后的ga目录。
运行下面命令:
$ rename *.C *.cpp
进入 examples 目录运行相同命令。
Step 2: 新建解决方案和工程
打开 Microsoft Visual C++,文件菜单下选择新建 >
对话框左边的项目类型选择 下的常规。
对话框右边的模板选择空项目。
输入项目名称。本例中,项目名称为 ga。
输入或浏览项目位置。本例假设位置在GAlib 解压目录下的子文件夹 projects。例如, C:\galib247\projects 。
输入解决方案名称,例如 vcpp2005 。选择创建解决方案的目录。
创建解决方案后,解决方案资源管理器中顶项显示为。ga 项目显示在其下,包括三个子项:
Step 3: 导入源文件和头文件
右击项目ga,选择添加 > 现有项...。浏览至ga目录,选择全部文件然后单击添加。
Step 4: 修改源码中引用的文件名
因为第一步 step 1 重命名了一些文件,所以需要替换源码中对这些文件的引用。选择在文件中替换,用每一行中新文本替换原始文本,需要替换的内容见下表
需要替换的文本原始文本 | 新文本 |
---|
<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> |
以下替换不必需但符合标准 C++:
可选替换文本原始文本 | 新文本 |
---|
<stdio.h> | <cstdio> |
<stdlib.h> | <cstdlib> |
<assert.h> | <cassert> |
<limits.h> | <climits> |
<time.h> | <ctime> |
<math.h> | <cmath> |
<string.h> | <cstring> |
Step 5: 设置项目属性
设置“配置属性”以下项:
-
- =
- =
-
- = ..\..\..
-
- = _CRT_SECURE_NO_DEPRECATE
-
- = 不使用预编译头
-
- =
Step 6: 生成项目
Visual C++ 默认解决方案配置为 Debug,若不需要调试 GAlib 代码,将解决方案配置改为
选择生成菜单下的生成 ga 生成项目。
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 Next to skip the first page.
Check in the group and un-check the check box.
Click Finish 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 Add.
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 OK.
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.
Links
- The GAlib Mailing List