linux下安裝protobuf及cmake編譯

一.protobuf 安裝git

protobuf版本:2.6.1github

下載地址:https://github.com/google/protobuf/archive/v2.6.1.zipweb

解壓以後進入目錄ruby

修改autogen.shcurl

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內的上述內容修改成ui

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.shgoogle

./autogen.shurl

目錄中就會生成出.configure文件code

接着運行blog

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

 

 

                                                                                                                 若是你以爲對你有用請付款

相關文章
相關標籤/搜索