protobuf編譯( 官方說明)

Copyright 2008 Google Inc.

https://developers.google.com/protocol-buffers/

C++ Installation - Unix

To build protobuf from source, the following tools are needed:

  • autoconf
  • automake
  • libtool
  • curl (used to download gmock)
  • make
  • g++
  • unzip

On Ubuntu, you can install them with:

$ sudo apt-get install autoconf automake libtool curl make g++ unzip

On other platforms, please use the corresponding package managing tool to
install them before proceeding.

If you get the source from github, you need to generate the configure script
first:

$ ./autogen.sh

This will download gmock source (which is used for C++ Protocol Buffer
unit-tests) to the current directory and run automake, autoconf, etc.
to generate the configure script and various template makefiles.

You can skip this step if you are using a release package (which already
contains gmock and the configure script).

To build and install the C++ Protocol Buffer runtime and the Protocol
Buffer compiler (protoc) execute the following:

$ ./configure
$ make
$ make check
$ sudo make install
$ sudo ldconfig # refresh shared library cache.

If "make check" fails, you can still install, but it is likely that
some features of this library will not work correctly on your system.
Proceed at your own risk.

For advanced usage information on configure and make, please refer to the
autoconf documentation:

http://www.gnu.org/software/autoconf/manual/autoconf.html#Running-configure-Scripts

Hint on install location

By default, the package will be installed to /usr/local. However,
on many platforms, /usr/local/lib is not part of LD_LIBRARY_PATH.
You can add it, but it may be easier to just install to /usr
instead. To do this, invoke configure as follows:

./configure --prefix=/usr

If you already built the package with a different prefix, make sure
to run "make clean" before building again.

Compiling dependent packages

To compile a package that uses Protocol Buffers, you need to pass
various flags to your compiler and linker. As of version 2.2.0,
Protocol Buffers integrates with pkg-config to manage this. If you
have pkg-config installed, then you can invoke it to get a list of
flags like so:

pkg-config --cflags protobuf         # print compiler flags
pkg-config --libs protobuf           # print linker flags
pkg-config --cflags --libs protobuf  # print both

For example:

c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf`

Note that packages written prior to the 2.2.0 release of Protocol
Buffers may not yet integrate with pkg-config to get flags, and may
not pass the correct set of flags to correctly link against
libprotobuf. If the package in question uses autoconf, you can
often fix the problem by invoking its configure script like:

configure CXXFLAGS="$(pkg-config --cflags protobuf)" \
          LIBS="$(pkg-config --libs protobuf)"

This will force it to use the correct flags.

If you are writing an autoconf-based package that uses Protocol
Buffers, you should probably use the PKG_CHECK_MODULES macro in your
configure script like:

PKG_CHECK_MODULES([protobuf], [protobuf])

See the pkg-config man page for more info.

If you only want protobuf-lite, substitute "protobuf-lite" in place
of "protobuf" in these examples.

Note for Mac users

For a Mac system, Unix tools are not available by default. You will first need
to install Xcode from the Mac AppStore and then run the following command from
a terminal:

$ sudo xcode-select --install

To install Unix tools, you can install "port" following the instructions at
https://www.macports.org . This will reside in /opt/local/bin/port for most
Mac installations.

$ sudo /opt/local/bin/port install autoconf automake libtool

Then follow the Unix instructions above.

Note for cross-compiling

The makefiles normally invoke the protoc executable that they just
built in order to build tests. When cross-compiling, the protoc
executable may not be executable on the host machine. In this case,
you must build a copy of protoc for the host machine first, then use
the --with-protoc option to tell configure to use it instead. For
example:

./configure --with-protoc=protoc

This will use the installed protoc (found in your $PATH) instead of
trying to execute the one built during the build process. You can
also use an executable that hasn't been installed. For example, if
you built the protobuf package for your host machine in ../host,
you might do:

./configure --with-protoc=../host/src/protoc

Either way, you must make sure that the protoc executable you use
has the same version as the protobuf source code you are trying to
use it with.

Note for Solaris users

Solaris 10 x86 has a bug that will make linking fail, complaining
about libstdc++.la being invalid. We have included a work-around
in this package. To use the work-around, run configure as follows:

./configure LDFLAGS=-L$PWD/src/solaris

See src/solaris/libstdc++.la for more info on this bug.

Note for HP C++ Tru64 users

To compile invoke configure as follows:

./configure CXXFLAGS="-O -std ansi -ieee -D__USE_STD_IOSTREAM"

Also, you will need to use gmake instead of make.

Note for AIX users

Compile using the IBM xlC C++ compiler as follows:

./configure CXX=xlC

Also, you will need to use GNU make (gmake) instead of AIX make.

C++ Installation - Windows

If you only need the protoc binary, you can download it from the release
page:

https://github.com/google/protobuf/releases

In the downloads section, download the zip file protoc-$VERSION-win32.zip.
It contains the protoc binary as well as public proto files of protobuf
library.

To build from source using Microsoft Visual C++, see cmake/README.md.

To build from source using Cygwin or MinGW, follow the Unix installation
instructions, above.

Binary Compatibility Warning

Due to the nature of C++, it is unlikely that any two versions of the
Protocol Buffers C++ runtime libraries will have compatible ABIs.
That is, if you linked an executable against an older version of
libprotobuf, it is unlikely to work with a newer version without
re-compiling. This problem, when it occurs, will normally be detected
immediately on startup of your app. Still, you may want to consider
using static linkage. You can configure this package to install
static libraries only using:

./configure --disable-shared

Usage

The complete documentation for Protocol Buffers is available via the
web at:

https://developers.google.com/protocol-buffers/
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末脚乡,一起剝皮案震驚了整個濱河市渤弛,隨后出現(xiàn)的幾起案子嵌纲,更是在濱河造成了極大的恐慌,老刑警劉巖奸笤,帶你破解...
    沈念sama閱讀 222,000評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件赞庶,死亡現(xiàn)場離奇詭異肤寝,居然都是意外死亡,警方通過查閱死者的電腦和手機较鼓,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,745評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來违柏,“玉大人博烂,你說我怎么就攤上這事∈” “怎么了禽篱?”我有些...
    開封第一講書人閱讀 168,561評論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長馍惹。 經常有香客問我躺率,道長玛界,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,782評論 1 298
  • 正文 為了忘掉前任悼吱,我火速辦了婚禮慎框,結果婚禮上,老公的妹妹穿的比我還像新娘后添。我一直安慰自己笨枯,他們只是感情好,可當我...
    茶點故事閱讀 68,798評論 6 397
  • 文/花漫 我一把揭開白布吕朵。 她就那樣靜靜地躺著猎醇,像睡著了一般。 火紅的嫁衣襯著肌膚如雪努溃。 梳的紋絲不亂的頭發(fā)上硫嘶,一...
    開封第一講書人閱讀 52,394評論 1 310
  • 那天,我揣著相機與錄音梧税,去河邊找鬼沦疾。 笑死,一個胖子當著我的面吹牛第队,可吹牛的內容都是我干的哮塞。 我是一名探鬼主播,決...
    沈念sama閱讀 40,952評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼凳谦,長吁一口氣:“原來是場噩夢啊……” “哼忆畅!你這毒婦竟也來了?” 一聲冷哼從身側響起尸执,我...
    開封第一講書人閱讀 39,852評論 0 276
  • 序言:老撾萬榮一對情侶失蹤家凯,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后如失,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體绊诲,經...
    沈念sama閱讀 46,409評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 38,483評論 3 341
  • 正文 我和宋清朗相戀三年褪贵,在試婚紗的時候發(fā)現(xiàn)自己被綠了掂之。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,615評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡脆丁,死狀恐怖世舰,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情槽卫,我是刑警寧澤跟压,帶...
    沈念sama閱讀 36,303評論 5 350
  • 正文 年R本政府宣布,位于F島的核電站晒夹,受9級特大地震影響裆馒,放射性物質發(fā)生泄漏姊氓。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,979評論 3 334
  • 文/蒙蒙 一喷好、第九天 我趴在偏房一處隱蔽的房頂上張望翔横。 院中可真熱鬧,春花似錦梗搅、人聲如沸禾唁。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,470評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽荡短。三九已至,卻和暖如春哆键,著一層夾襖步出監(jiān)牢的瞬間掘托,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,571評論 1 272
  • 我被黑心中介騙來泰國打工籍嘹, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留闪盔,地道東北人。 一個月前我還...
    沈念sama閱讀 49,041評論 3 377
  • 正文 我出身青樓辱士,卻偏偏與公主長得像泪掀,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子颂碘,可洞房花燭夜當晚...
    茶點故事閱讀 45,630評論 2 359

推薦閱讀更多精彩內容