• Linux下编译cpp_redis


    下载

    cpp_redis的地址为https://github.com/Cylix/cpp_redis,以下载版本4.3.1为例,下载后文件为cpp_redis-4.3.1.tar.gz

    编译

    使用命令tar -zxvf cpp_redis-4.3.1.tar.gz进行解压,解压完成后文件夹cpp_redis-4.3.1中目录结构如下:

    [root@VM-12-15-centos cpp_redis-4.3.1]# ls -al
    total 212
    drwxrwxr-x 10 root root   4096 Feb  1  2018 .
    drwxr-xr-x  6 root root   4096 Nov 18 22:57 ..
    -rw-rw-r--  1 root root    960 Feb  1  2018 .appveyor.yml
    drwxrwxr-x  3 root root   4096 Feb  1  2018 assets
    -rw-rw-r--  1 root root  10718 Feb  1  2018 CHANGELOG.md
    -rw-rw-r--  1 root root   5929 Feb  1  2018 .clang-format
    -rwxrwxr-x  1 root root    161 Feb  1  2018 clang_format.sh
    -rw-rw-r--  1 root root   6574 Feb  1  2018 CMakeLists.txt
    -rw-rw-r--  1 root root   1499 Feb  1  2018 CONTRIBUTING.md
    -rw-rw-r--  1 root root    291 Feb  1  2018 cpp_redis.pc.in
    drwxrwxr-x  4 root root   4096 Feb  1  2018 docs
    -rw-rw-r--  1 root root 107653 Feb  1  2018 .doxygen
    drwxrwxr-x  2 root root   4096 Feb  1  2018 examples
    -rw-rw-r--  1 root root    414 Feb  1  2018 .gitignore
    -rw-rw-r--  1 root root    100 Feb  1  2018 .gitmodules
    drwxrwxr-x  3 root root   4096 Feb  1  2018 includes
    -rw-rw-r--  1 root root   1107 Feb  1  2018 LICENSE
    drwxrwxr-x  2 root root   4096 Feb  1  2018 msvc15
    -rw-rw-r--  1 root root   2786 Feb  1  2018 README.md
    drwxrwxr-x  6 root root   4096 Feb  1  2018 sources
    drwxrwxr-x  2 root root   4096 Feb  1  2018 tacopie
    drwxrwxr-x  3 root root   4096 Feb  1  2018 tests
    -rw-rw-r--  1 root root    928 Feb  1  2018 .travis.yml
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    注意此时tacopie为空文件夹,需要自己手动进行下载。(在cpp_redis的主界面上,通过下图中标注tacopie链接可直接跳转到tacopie的Github页面)

    在这里插入图片描述

    下载tacopie后,将其中的所有数据放入到cpp_redis-4.3.1目录下空的tacopie中。(这里以tacopie-3.2.0为例)

    使用命令mkdir build创建构建目录,然后进入build中(cd build),使用命令cmake ..构建工程,

    [root@VM-12-15-centos build]# cmake ..
    -- The CXX compiler identification is GNU 8.5.0
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /test/cpp_redis-4.3.1/build
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    再使用命令cmake --build .进行编译:

    [root@VM-12-15-centos build]# cmake --build .
    Scanning dependencies of target tacopie
    [  2%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/builders/bulk_string_builder.cpp.o
    [  5%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/builders/integer_builder.cpp.o
    [  8%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/builders/error_builder.cpp.o
    [ 10%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/builders/array_builder.cpp.o
    [ 13%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/builders/builders_factory.cpp.o
    [ 16%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/builders/simple_string_builder.cpp.o
    [ 18%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/builders/reply_builder.cpp.o
    [ 21%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/core/client.cpp.o
    [ 24%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/core/reply.cpp.o
    [ 27%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/core/sentinel.cpp.o
    [ 29%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/core/subscriber.cpp.o
    [ 32%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/misc/logger.cpp.o
    [ 35%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/network/redis_connection.cpp.o
    [ 37%] Building CXX object tacopie/CMakeFiles/tacopie.dir/__/sources/network/tcp_client.cpp.o
    [ 40%] Building CXX object tacopie/CMakeFiles/tacopie.dir/sources/network/io_service.cpp.o
    [ 43%] Building CXX object tacopie/CMakeFiles/tacopie.dir/sources/network/tcp_server.cpp.o
    [ 45%] Building CXX object tacopie/CMakeFiles/tacopie.dir/sources/network/tcp_client.cpp.o
    [ 48%] Building CXX object tacopie/CMakeFiles/tacopie.dir/sources/network/common/tcp_socket.cpp.o
    [ 51%] Building CXX object tacopie/CMakeFiles/tacopie.dir/sources/utils/error.cpp.o
    [ 54%] Building CXX object tacopie/CMakeFiles/tacopie.dir/sources/utils/thread_pool.cpp.o
    [ 56%] Building CXX object tacopie/CMakeFiles/tacopie.dir/sources/utils/logger.cpp.o
    [ 59%] Building CXX object tacopie/CMakeFiles/tacopie.dir/sources/network/unix/unix_self_pipe.cpp.o
    [ 62%] Building CXX object tacopie/CMakeFiles/tacopie.dir/sources/network/unix/unix_tcp_socket.cpp.o
    Linking CXX static library ../lib/libtacopie.a
    [ 62%] Built target tacopie
    Scanning dependencies of target cpp_redis
    [ 64%] Building CXX object CMakeFiles/cpp_redis.dir/sources/builders/bulk_string_builder.cpp.o
    [ 67%] Building CXX object CMakeFiles/cpp_redis.dir/sources/builders/integer_builder.cpp.o
    [ 70%] Building CXX object CMakeFiles/cpp_redis.dir/sources/builders/error_builder.cpp.o
    [ 72%] Building CXX object CMakeFiles/cpp_redis.dir/sources/builders/array_builder.cpp.o
    [ 75%] Building CXX object CMakeFiles/cpp_redis.dir/sources/builders/builders_factory.cpp.o
    [ 78%] Building CXX object CMakeFiles/cpp_redis.dir/sources/builders/simple_string_builder.cpp.o
    [ 81%] Building CXX object CMakeFiles/cpp_redis.dir/sources/builders/reply_builder.cpp.o
    [ 83%] Building CXX object CMakeFiles/cpp_redis.dir/sources/core/client.cpp.o
    [ 86%] Building CXX object CMakeFiles/cpp_redis.dir/sources/core/reply.cpp.o
    [ 89%] Building CXX object CMakeFiles/cpp_redis.dir/sources/core/sentinel.cpp.o
    [ 91%] Building CXX object CMakeFiles/cpp_redis.dir/sources/core/subscriber.cpp.o
    [ 94%] Building CXX object CMakeFiles/cpp_redis.dir/sources/misc/logger.cpp.o
    [ 97%] Building CXX object CMakeFiles/cpp_redis.dir/sources/network/redis_connection.cpp.o
    [100%] Building CXX object CMakeFiles/cpp_redis.dir/sources/network/tcp_client.cpp.o
    Linking CXX static library lib/libcpp_redis.a
    [100%] Built target cpp_redis
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44

    使用命令make install DESTDIR=XXX进行安装:

    [root@VM-12-15-centos build]# make install DESTDIR=XXX
    [ 62%] Built target tacopie
    [100%] Built target cpp_redis
    Install the project...
    -- Install configuration: ""
    -- Installing: XXX/test/cpp_redis-4.3.1/build/lib
    -- Installing: XXX/test/cpp_redis-4.3.1/build/bin
    -- Installing: XXX/usr/local/lib
    -- Installing: XXX/usr/local/lib/pkgconfig
    -- Installing: XXX/usr/local/lib/pkgconfig/cpp_redis.pc
    -- Installing: XXX/usr/local/lib/libtacopie.a
    -- Installing: XXX/usr/local/lib/libcpp_redis.a
    CMake Error at cmake_install.cmake:64 (FILE):
      file INSTALL cannot find "/test/cpp_redis-4.3.1/build/bin".
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    安装完成后,将tacopie和cpp_redis的头文件及库文件整理分别放入各自的include目录及lib目录,最后的目录结构如下(去掉其中无用的文件、文件夹):

    [root@VM-12-15-centos test]# tree tacopie
    tacopie
    |-- include
    |   `-- tacopie
    |       |-- network
    |       |   |-- io_service.hpp
    |       |   |-- self_pipe.hpp
    |       |   |-- tcp_client.hpp
    |       |   |-- tcp_server.hpp
    |       |   `-- tcp_socket.hpp
    |       |-- tacopie
    |       `-- utils
    |           |-- error.hpp
    |           |-- logger.hpp
    |           |-- thread_pool.hpp
    |           `-- typedefs.hpp
    `-- lib
        `-- libtacopie.a
    
    5 directories, 11 files
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    [root@VM-12-15-centos test]# tree cpp_redis
    cpp_redis
    |-- include
    |   `-- cpp_redis
    |       |-- builders
    |       |   |-- array_builder.hpp
    |       |   |-- builder_iface.hpp
    |       |   |-- builders_factory.hpp
    |       |   |-- bulk_string_builder.hpp
    |       |   |-- error_builder.hpp
    |       |   |-- integer_builder.hpp
    |       |   |-- reply_builder.hpp
    |       |   `-- simple_string_builder.hpp
    |       |-- core
    |       |   |-- client.hpp
    |       |   |-- reply.hpp
    |       |   |-- sentinel.hpp
    |       |   `-- subscriber.hpp
    |       |-- cpp_redis
    |       |-- helpers
    |       |   `-- variadic_template.hpp
    |       |-- impl
    |       |   `-- client.ipp
    |       |-- misc
    |       |   |-- error.hpp
    |       |   |-- logger.hpp
    |       |   `-- macro.hpp
    |       `-- network
    |           |-- redis_connection.hpp
    |           |-- tcp_client.hpp
    |           `-- tcp_client_iface.hpp
    `-- lib
        `-- libcpp_redis.a
    
    9 directories, 22 files
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    使用

    直接参考cpp_redis的example即可。注意都要包含和链接这两个库tacopie及cpp_redis。

  • 相关阅读:
    从Redis的架构看Redis使用优化方面的几个要点
    OTA升级常见错误码汇总-CSDN博客
    MindSpore:有关卷积层的问题
    计算机竞赛 基于计算机视觉的身份证识别系统
    dubbo SPI机制
    java计算机毕业设计敬老福利院管理源码+mysql数据库+系统+lw文档+部署
    GD32 RT-Thread PWM驱动函数
    web简史及网络基础
    智慧城市行业资料学习目录
    DBA 数据库管理 . 内连接.外链接
  • 原文地址:https://blog.csdn.net/xp178171640/article/details/127931101