ubuntu下安装Boost库、LOKI库、log4xx库

 最近把自己的工作平台都迁到ubuntu上了,所以要把环境搭起来,首先要安装的是Boost库。 Boost库可以说是STL里非常好用的一个库。
        1、获得Boost库
             直接在命令行中输入:apt-get install libboost-dev libboost-dbg libboost-doc bcp libboost-*,但可能得不到,也可以到Boost的主页上(http://www.boost.org/users/download/)自己下载安装包。下载可能用到SVN客户端,执行语句:
sudo apt-get install subversion。SVN客户端就安装好了,我们就可以checkout最新的版本了:
svn co http://svn.boost.org/svn/boost/trunk boost-trunk。
        2、安装GCC、G++编译器
                 执行:sudo apt-get install build-essential
        3、安装依赖库
             需要先安装zlib, bzlib, python2.5-dev。
            1)安装python2.5-dev,
                   执行:sudo apt-get install python2.5-dev就行了
                   
                   也可以下载安装包.tar.gz2,安装时看README,注意安装的目录位置,
                    在安装boost时编译configure里加上PYTHON_LIB_PATH=/usr/local/lib/python2.5
PYTHON_INCLUDES=/usr/local/include/python2.5两个参数
            2)安装zlib
                   wget http://www.zlib.net/zlib-1.2.3.tar.gz
                   ./configure
                    make
                    make install
             3)安装bzlib
                    wget http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
                    make
                    make install
          4、安装boost
                    sudo -i  //改为超级用户
                    cd boost_1_38/tools/jam/src
                    ./build.sh
                    cd bin.linuxx86
                    export PATH=$PATH:/home/qiuzhiguang/boost_1_38/tools/jam/src/bin.linuxx86 //把bjam程序所在目录设为搜索目录
                    cd boost_1_38
                    bjam install
                    cd /usr/local/include/boost_1_38
                    mv boost ./../
                    将 /usr/local/lib 以及 /usr/local/lib64 两个路径添加到 /etc/ld.so.conf 末尾
                    /sbin/ ldconfig
            5、测试boost库
                  #include <iostream>
                  #include <boost/scoped_ptr.hpp>

                  int main(int argc,char **argv)
                  {
                       int pcr = 100;
                       boost::scoped_ptr <int> m_lastPCR;
                       m_lastPCR.reset(new int(pcr));
                       std::cout<<"boost: "<<*m_lastPCR<<std::endl;
                       return 0;
                  }

  接下来就可以安装loki库了。loki库主要用了里面的Singleton,单键模式,只生成一个对象。
         1.download loki-0.1.6.tar.gz from http://sourceforge.org/
         2.sudo -i
         3.tar xzf loki-0.1.6.tar.gz
         4.cd loki-0.1.6
         5.修改Makefile
               把有关test目录下的编译去掉
               因为这里面可能编译不过,但也没有什么用。
         6.make
         7.cd loki-0.1.6/include
         8.cp –r loki /usr/include
         9.cd loki-0.1.6/lib
        10.cp –r * /usr/lib

        11安装log4cxx
             1)安装libtool软件包
                    de>$sudo apt-get install libtool
        2)de>安装automake
                    de>$sudo apt-get install automake
        3)生成configure文件
           $./autogen.sh
        4)生成Makefile文件
           $./configure
        5)make && make install
de>        12测试3个库
#define LOKI_CLASS_LEVEL_THREADING//使得ClassLevelLockable生效
#include <loki/Singleton.h>
#include <log4cxx/logger.h>
#include <boost/scoped_ptr.hpp>
using namespace log4cxx;

class Speak
{
    public:
        Speak();
        void sayHello(const char *);
        void set(const int);
        int get();
    private:
        int count;
        log4cxx::LoggerPtr m_logger;
};
typedef Loki::SingletonHolder <Speak, Loki::CreateUsingNew, Loki::DefaultLifetime, Loki::ClassLevelLockable> SS;
Speak::Speak()
{
    m_logger = Logger::getLogger("qiuzhiguang");
}
void Speak::sayHello(const char *str)
{
    std::cout<<"Hello "<<str<<"/n";
}
void Speak::set(const int n)
{
    count = n;
}
int Speak::get()
{
    return count;
}

int main(int argc,char **argv)
{
    int pcr = 100;
    boost::scoped_ptr <int> m_lastPCR;
    SS::Instance().sayHello("world");
    m_lastPCR.reset(new int(pcr));
    std::cout<<"boost: "<<*m_lastPCR<<std::endl;
    return 0;
}

你可能感兴趣的:(ubuntu下安装Boost库、LOKI库、log4xx库)