1. 程式人生 > >linux下安裝protobuf及cmake編譯

linux下安裝protobuf及cmake編譯

light present mini require fetching AS exp web .gz

一.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)

如果你覺得對你有用請付款

技術分享圖片

linux下安裝protobuf及cmake編譯