learnvst
learnvst

Reputation: 16195

Can't build google protocol buffers tutorial on mac

I am trying to build the c++ tutorial examples on a mac with no success so far. The tutorial is here . . . .

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

I cannot use the makefile to build the examples as there is no pkg-confic command. I get the following error . .

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

I can build the compiler and library just fine using the following

./configure --prefix=/usr
make
make check
make install

I can use protoc to compile the proto file included with the tutorial ok, but I cannot link the executables for some reason. I get the following . . .

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

...but the library is definitely in /usr/lib. I'm probably making a really basic error here.

Upvotes: 0

Views: 5769

Answers (3)

evernoob
evernoob

Reputation: 181

just FYI on 3.5.0 on Mac OS.

I changed lines in Makefile for protobuf 3.5.0. cpp compilation.

First, let me say I have no sudo rights on this machine and could not make install in "the usual" place so it is in ~/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`

[ I put ~ (tilde) in there but in my actual Makefile I put the full path... just obfuscating a bit. ]

The Java compiles worked as advertised.

I can't do python because getting pip or running easy_install need sudo.

Upvotes: 0

Adebiyi Abdurrahman
Adebiyi Abdurrahman

Reputation: 191

@Learvst Like you I don't have pkg-config installed on my Mac See the below for my MAC version

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

So I did the following

A. Get the protobuf library location

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)

This indicates the protoc compiler uses the library "libprotobuf.8.dylib"

B. Then I compiled

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

C. Voila I had my program "add_person_cpp" ready to be used

abd@harvey-specter$ c./add_person_cpp

Usage:  ./add_person_cpp ADDRESS_BOOK_FILE

Hope it helps

Upvotes: 0

bames53
bames53

Reputation: 88215

The link flag should be

-lprotobuf

Upvotes: 4

Related Questions