• ubuntu16.04源码编译安装Poco1.7.8


    首先,做编译前准备,编译安装OPENSSL等包,为编译Poco准备依赖包。

    1. OPENSSL的编译安装(以1.0.0e为准)
            源码下载地址:http://distfiles.macports.org/openssl/openssl-1.0.2k.tar.gz
            下载后按如下指令进行编译安装:
            tar -zxvf openssl-1.0.0e.tar.gz

            cd openssl-1.0.2k

    ./config shared --prefix=/usr/local/openssl --openssldir=/usr/lib/openssl
    #shared 表示生成动态库
    #prefix 表示安装目录
    #openssldir 表示配置文件目录,ubuntu默认是/usr/lib/openssl,若设置其他目录,执行openssl命令时会有警告.
    #make
    #make install

      设置环境变量
      vi ~/.bashrc
      在最后一行添加export PATH=$PATH:/usr/local/openssl/bin 保存退出,使用source ~/.bashrc使其立即生效。

      创建符号链接(第一个必须做,不然sudo openssl执行失败)
      #ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
      #ln -s /usr/local/ssl/openinclude/openssl /usr/include/openssl

      刷新动态库配置(实验不做也可以)

      #vi /etc/ld.so.conf

      在文件末尾加入
      /usr/local/ssl/lib

      测试(如果你没有创建符号链接,下面的命令要带上具体的路径)
      openssl version -a

      

    如果遇到:Makefile:594: recipe for target 'install_docs' failed 

    解决方法:
      rm -f /usr/bin/pod2man

           或直接通过命令安装:

          sudo apt-get install openssl

          sudo apt-get install libssl-dev

    2. 编译安装Poco
            源码下载地址:https://pocoproject.org/releases/poco-1.8.0/poco-1.8.0.tar.gz

            tar -xzvf poco-1.8.0.tar.gz

            cd poco-1.8.0

             ./configure --no-tests --no-samples  --prefix=/usr/local/poco --static --shared  #/usr/local/Poco为编译好后头文件和库的安装位置
            make
            make install
    到此Poco就安装完成了。

     测试:

    test.cpp

    #include <Poco/BasicEvent.h>
    #include <Poco/Delegate.h>
    #include <iostream>
    
    using Poco::BasicEvent;
    using Poco::Delegate;
    
    class Source
    {
    public:
        BasicEvent<int> theEvent;
    
        void fireEvent(int n)
        {
            theEvent(this, n);
        }
    };
    
    class Target
    {
    public:
        void onEvent(const void* pSender, int& arg)
        {
            std::cout << "onEvent: " << arg << std::endl;
        }
    };
    
    int main(int argc, char** argv)
    {
        Source source;
        Target target;
    
        source.theEvent += Delegate<Target, int>(
            &target, &Target::onEvent);
    
        source.fireEvent(42);
    
        source.theEvent -= Delegate<Target, int>(
            &target, &Target::onEvent);
    
        return 0;
    }

    Makefile

    SRC = ./test.cpp
    OBJ = $(SRC:%.cpp=%.o)
    EXEC = test
    
    CC = g++
    FLAGS = -O2
    #-L表示在链接时要链接库的路径,但是在生成的ELF文件中,并不包含库的路径,需要LD_LIBRARY_PATH中有这个库的路径
    #-Wl,-rpath不仅仅表示在链接时要查找这个路径下的库,还要把这个路径写到ELF文件中,且查找顺序优先于$LD_LIBRARY_PATH
    LIB = -L/usr/local/Poco/lib/
    LIB_ELF = -Wl,-rpath,/usr/local/Poco/lib/
    LIB_POCO = -lPocoUtil -lPocoXML -lPocoNet -lPocoFoundation
    INCLUDE = -I/usr/local/Poco/include
    
    test:$(OBJ)
        $(CC) $^ $(LIB) $(LIB_POCO) $(FLAGS) -o $(EXEC)
    clean:
        rm -f test.o
    
    %.o:%.cpp
        $(CC) -c $(INCLUDE) $(FLAGS) $< -o $@
    .PHONY:test
  • 相关阅读:
    完成了一次子网站向顶级网站的迁移
    Sharepoint中子网站迁移到顶级网站的方法
    Chain Of Responsibility——设计模式学习笔记
    短信PDU编码解析
    Decorator模式——设计模式学习笔记
    adb常用命令和logcat使用
    Explicit——谨慎定义隐式类型转换函数
    FlyWeight模式——设计模式学习笔记
    Facade模式——设计模式学习笔记
    宏——#define与#undef
  • 原文地址:https://www.cnblogs.com/GnibChen/p/8630137.html
Copyright © 2020-2023  润新知