protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Documentation is missing build/linking instructions

Open hk0i opened this issue 2 years ago • 1 comments

What version of protobuf and what language are you using?

Version:

protoc --version
libprotoc 3.21.8

Language: C++

What operating system (Linux, Windows, ...) and version?

Mac OS 12.6 / Apple Silicon ARM64

uname -srm
Darwin 21.6.0 arm64

What runtime / compiler are you using (e.g., python version or gcc version)

g++ --version
Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

What did you do?

Read the manual

Steps to reproduce the behavior:

  1. Install via homebrew
brew install protobuf
  1. Read how to write a message

What did you expect to see

Instructions on how to compile code sample and link against libraries.

What did you see instead?

Absolutely no build instructions.

Could not find any details on compiling in any of the github readmes or any of the online C++ docs.

What else did you try?

  1. Searching Google on "how to build protobuf"
  2. Guessing random build configurations:
llvm-g++ main.cc
In file included from main.cc:4:
./addressbook.pb.h:10:10: fatal error: 'google/protobuf/port_def.inc' file not found
#include <google/protobuf/port_def.inc>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
g++ -L/opt/homebrew/lib -lprotobuf  main.cc
In file included from main.cc:4:
./addressbook.pb.h:10:10: fatal error: 'google/protobuf/port_def.inc' file not found
#include <google/protobuf/port_def.inc>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

hk0i avatar Oct 26 '22 06:10 hk0i

Was able to figure it out on my own, after running into several other issues (like c++11 requirements)

g++ -I/opt/homebrew/include -L/opt/homebrew/lib -lprotobuf -std=c++11 main.cc addressbook.pb.cc -o addressbook

I still think it would be worth mentioning in the actual documentation, however.

hk0i avatar Oct 26 '22 17:10 hk0i

I'm glad you were able to figure it out!

I agree it is worth documenting, and this is something we have plans for but haven't had time to prioritize. Any contributions to the docs with what you learned would be greatly appreciated!

deannagarcia avatar Nov 03 '22 16:11 deannagarcia

brew installs libprotoc 3.19.1 and not the latest version. Any fix for this? Already tried brew upgrade protobuf , it warns me that the latest is already installed

nikiexpo avatar Nov 15 '22 12:11 nikiexpo

The protobuf team does not maintain installation through homebrew. My understanding is that is maintained by homebrew directly, so I would reach out to them.

deannagarcia avatar Nov 15 '22 18:11 deannagarcia

I was able to build pycld3 which is based on libprotoc on M1 MacBook Air by installing latest protobuf 21.12 and running

export LDFLAGS=-L/opt/homebrew/lib      
export CPPFLAGS=-I/opt/homebrew/include 

DotIN13 avatar May 29 '23 07:05 DotIN13

I was able to build pycld3 which is based on libprotoc on M1 MacBook Air by installing latest protobuf 21.12 and running

export LDFLAGS=-L/opt/homebrew/lib      
export CPPFLAGS=-I/opt/homebrew/include 

Thank you very much for that solution it worked on my M1 MacBook Pro also 👍 I've stumbled upon some other solution if that doesn't work for you maybe the other does.(https://github.com/google/cld3/issues/80)

pip install --global-option=build_ext  --global-option="-I/opt/homebrew/Cellar/protobuf/21.12/include" --global-option="-L/opt/homebrew/Cellar/protobuf/21.12/lib" gcld3

osnortb avatar Jun 02 '23 12:06 osnortb