zoukankan      html  css  js  c++  java
  • linux下安装protobuf及cmake编译

    一.protobuf 安装

    protobuf版本:2.6.1

    下载地址:https://github.com/google/protobuf/archive/v2.6.1.zip

    解压之后进入目录

    修改autogen.sh

    echo "Google Test not present.  Fetching gtest-1.5.0 from the web..."
    curl http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2 | tar jx
    mv gtest-1.5.0 gtest
    

     将autogen.sh内的上述内容修改为

    wget https://github.com/google/googletest/archive/release-1.5.0.tar.gz
    tar xzvf release-1.5.0.tar.gz
    mv googletest-release-1.5.0 gtest
    

     然后执行autogen.sh

    ./autogen.sh

    目录中就会生成出.configure文件

    接着运行

    ./configure
    make
    make check
    make install
    

     设置环境变量

    sudo vi /etc/profile
    export PATH=$PATH:/usr/local/bin
    export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
    cd ~
    vi .profile
    export PATH=$PATH:/usr/local/bin
    export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
    

     配置动态链接库路径

    sudo vi /etc/ld.so.conf
    include /usr/local/lib
     sudo ldconfig

    二.编写CMakeLists

    cmake_minimum_required (VERSION 2.8)
    
    project (Demo1)
    SET(SRC_LIST test1.cpp)
    # Find required protobuf package
    find_package(Protobuf REQUIRED)
    if(PROTOBUF_FOUND)
       message(STATUS "protobuf library found")
    else()
        message(FATAL_ERROR "protobuf library is needed but cant be found")
    endif()
    include_directories(${PROTOBUF_INCLUDE_DIRS})
    INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
    PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS test1.proto)
    
    ADD_EXECUTABLE(Demo1 ${SRC_LIST} ${PROTO_SRCS} ${PROTO_HDRS})
    
    target_link_libraries(Demo1 ${PROTOBUF_LIBRARIES})
    
    #add_executable(Demo test1.cpp)
    

                                                                                                                     如果你觉得对你有用请付款

  • 相关阅读:
    jquery 实现可编辑div
    【ubuntu firefox】 Firefox is already running, but is not responding
    PO标准form的一点疑问
    hdu3488Tour KM算法
    经典算法学习——归并排序
    Linux 安装Redis全过程日志
    算法竞赛入门经典 习题 2-10 排列(permutation)
    每日一支TED——弗兰斯·兰庭:为动物发声的摄影作品——2015年6月3日
    Linux用户密码策略
    chage命令
  • 原文地址:https://www.cnblogs.com/aelite/p/9026885.html
Copyright © 2011-2022 走看看