Linux上用Eclipse CDT开发c++项目的实例

Linux上用Eclipse CDT开发c++项目的实例


我们以 boost的reg_ex为例子


首先,我们需要安装Boost,这不是本文要介绍的主要内容,这里只简单说一下

找好安装包以后,执行./configure,make,make install。

Boost默认安装在/usr/local目录下,头文件在/include目录下,库在/lib目录 下


在/usr/lib下执行ln -fs /usr/local/lib/libboost-regex-gcc41-mt-1_38.so.1.38.0 ./libboost-regex-gcc41-mt-1_38.so.1.38.0


如何安装Eclipse CDT请参考下面这两篇文章:

http://blog.csdn.net/ghlfllz/article/details/5917762

http://blog.csdn.net/ghlfllz/article/details/5917760


启动Eclipse后,建立一个空白的c++项目,

新建StdAfx.h文件,输入如下代码:

#include <stdio.h>

#include <iostream>


新建BoostSample.cpp文件,输入如下代码:

#include "StdAfx.h"

#include <boost/regex.hpp>

#include <iostream>

#include <string>


int main( int argc, char *argv[] )

{

    std::string line;

    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );


    while ( std::cin )

    {

        std::getline( std::cin, line );

        boost::smatch matches;

        if ( boost::regex_match( line, matches, pat ) )

            std::cout << matches[2] << std::endl;

    }


    return 0;

}


在项目上右键选Property - C/C++ General - Includes - GNU C++中添加 /usr/local/include/boost-1_38

在Property - C/C++ General - Library Paths中添加/usr/local/lib


在Propery - C/C++ Build - Settings - Tool Settings - GCC C++ Compiler - Directories中添加/usr/local/include/boost-1_38

在Propery - C/C++ Build - Settings - Tool Settings - GCC c++ Liner - Librarys- librarys下添加boost_regex_gcc41-mt

在Propery - C/C++ Build - Settings - Tool Settings - GCC c++ Liner - Librarys-library search path中添加/usr/local/lib


至此相关设置全部完成,直接编译项目即可。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值