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

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

思念带着一种默默地忧伤,

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

相关文章:

你感兴趣的文章:

标签云: