无法在mac上构建谷歌协议缓存教程

时间:2012-04-20 15:37:08

标签: c++ macos protocol-buffers

我正在尝试在Mac上构建c ++教程示例,但到目前为止还没有成功。教程就在这里。 。 。 。

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

我不能使用makefile来构建示例,因为没有pkg-confic命令。我收到以下错误。 。

pkg-config --cflags protobuf  # fails if protobuf is not installed
/bin/sh: pkg-config: command not found
make: *** [add_person_cpp] Error 127

我可以使用以下

来构建编译器和库
./configure --prefix=/usr
make
make check
make install

我可以使用protoc来编译教程中包含的proto文件,但是由于某些原因我无法链接可执行文件。我得到以下内容。 。 。

$ g++ add_person.cc addressbook.pb.cc -L /usr/lib/ -l libprotobuf.a  -o write
ld: library not found for -llibprotobuf.a

...但是库肯定在/ usr / lib中。我可能在这里犯了一个非常基本的错误。

3 个答案:

答案 0 :(得分:4)

链接标志应为

-lprotobuf

答案 1 :(得分:0)

@Learvst和我一样,我没有在我的Mac上安装pkg-config 请参阅以下我的MAC版本

$sw_vers
ProductName:    Mac OS X
ProductVers
ion:    10.9.4
BuildVersion:   13E28

所以我做了以下

一个。获取protobuf库位置

abd@harvey-specter$ otool -L $(which protoc)

/usr/local/bin/protoc:
    /usr/local/lib/libprotobuf.8.dylib (compatibility version 9.0.0, current version 9.0.0)
    /usr/local/lib/libprotoc.8.dylib (compatibility version 9.0.0, current version 9.0.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

这表明protoc编译器使用了库" libprotobuf.8.dylib"

B中。然后我编译了

abd@harvey-specter$ c++ add_person.cc addressbook.pb.cc -o add_person_cpp -L/usr/local/lib -lprotobuf.8

℃。我有自己的节目" add_person_cpp"准备使用

abd@harvey-specter$ c./add_person_cpp

Usage:  ./add_person_cpp ADDRESS_BOOK_FILE

希望有所帮助

答案 2 :(得分:0)

仅适用于Mac OS上的3.5.0。

我在makefile中更改了protobuf 3.5.0的行。 cpp编译。

首先,让我说我在这台机器上没有sudo权限,无法在“通常”的地方安装,所以它在〜/ local / lib,bin,include。

    add_person_cpp: add_person.cc protoc_middleman
         #pkg-config --cflags protobuf  # fails if protobuf is not installed
         c++ add_person.cc addressbook.pb.cc -o add_person_cpp -lprotobuf -L~/local/lib -I~/local/include #`pkg-config --cflags --libs protobuf`

    list_people_cpp: list_people.cc protoc_middleman
         #pkg-config --cflags protobuf  # fails if protobuf is not installed
         c++ list_people.cc addressbook.pb.cc -o list_people_cpp -lprotobuf -L~/local/lib -I~/local/include #`pkg-config --cflags --libs protobuf`

[我把〜(代字号)放在那里,但在我的实际Makefile中,我把完整的路径...只是混淆了一点。 ]

Java编译按宣传方式工作。

我不能做python因为获取pip或运行easy_install需要sudo。

相关问题