eclipse配置boost

来源:互联网 发布:javimdb最新域名 编辑:程序博客网 时间:2024/06/05 21:12

由于工作需要,在eclipse上进行开发,但是得到一个问题是eclipse不支持boost,于是网上搜索很多教程,东拼西凑,终于完成了环境的搭建

写一个博客记录一下,以后用到可以查看,也可以帮助他人

1、安装Eclipse CPP  官网下载对应的c++版本eclipse压缩包

  将eclipse-cpp-kepler-SR2-win32-x86_64.zip解压到相应的开发硬盘目录中,注意目录名称中不要包含中文名称;
  在跟目录下双击打开eclipse.exe 应用程序,如果提示javaw.exe找不到需要先安装java环境
  java环境安装:官网下载,对应Windowsx86或者x64版本
  1、双击java, 安装到非C盘,例如 E:\java
  2、系统环境配置 在高级系统设置中选择,环境变量设置,path, 添加;E:\java\bin
  3、安装环境测试: 打开cmd  输入java 回车 出现java的用法提示信息
  现在可以运行eclipse.exe ,选择工作空间,例如E:\eclipse_workspace
 
2、安装MinGW 官网自行下载
  将 mingw.zip解压到C盘根目录下,这将在C盘中生成一个Mingw目录。(应该只编译了vs版本的文件)
     配置环境变量
     2.1 在PATH 中加入C:\mingw\bin 记得,里面有其他环境变量,需要用分号;隔开
     2.1 新建LIBRARY_PATH 变量,如果有的话再该值中加入 C:\mingw\lib,这是表准库的位置
     2.3 新建C_INCLUDEDE_PATH 变量,设置值为,C:\mingw\include 
     
     测试配置是否成功
      在cmd 中输入 
      gcc  -v 
      查看MinGW 版本
     
3、官网下载boost 安装包 
第一步:解压执行 根目录下的bootstrap.bat 脚本 生成两个可执行文件 b2.exe   bjam.exe
第二部: cmd 执行命令 切换到boost根目录, 执行“bjam --build-type=complete toolset=gcc stage”/或者/“b2 --build-type=complete toolset=gcc stage”
执行过程约40-60分钟,可能出现c1cpluse.exe中断错误,未找到准确结局方法,
boost 1-51 失败
boost 1-55 失败
boost 1-64 最新版本成功 采用64版本 

这种方式是生成 MinGW的GCC版本库文件,以.so 或者.a结尾的
生成到xxx\boost\stage\lib路径下,
第三步:由于boost是压缩包,直接解压就可以了(上面说法针对没有boost 编译好的版本的用户)
配置环境变量 ,在PATH中添加,"xxx\boost\stage\lib",注意以;结尾,最好注销或者重启电脑


第四部:测试
file -> new -> c++ project ->
->project name : boostTimer
->project type : hello world c++ project 
->toolchians:  MinGW GCC
右键 boostTimer
->properties -> c/c++ build -> setings
-> GCC c++ compiles 
-> Includes    添加 "D:\boost_1_64_0"
-> MinGW c++ Linker
->Libraries   -> Libraries (-l)     添加 boost_regex-mgw49-mt-1_64   (这里根据生成的版本选择)
-> Library search path (-L)   添加 "D:\boost_1_64_0\stage\lib"
测试程序:
#include <iostream>
#include <boost/timer.hpp>
#include <boost/progress.hpp>
using namespace std;
using namespace boost;


int main() {
timer t;
cout << "max timespan" << t.elapsed_max()/3600 << "h" << endl;
cout << "min timespan" << t.elapsed_min() << "s" << endl;
cout << "now  time" << t.elapsed() << "s" << endl;

{
progress_timer t;
for(int i = 0; i< 1000000000; i++)
{
;
}
cout << "first timer " << endl;
}
{
progress_timer t;
for(int i = 0; i< 1000000000; i++)
{
;
}
cout << "next timer " << endl;
}

cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}


输出:
max timespan596.523h
min timespan0.001s
now  time0s

first timer 
1.89 s


next timer 
1.89 s

!!!Hello World!!!