protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Using Library Without Download

Open Phlip79 opened this issue 9 years ago • 12 comments

I am trying to use the google protobuf library without having to download the whole library and run through ./configure, make, make check, ... I am currently putting the protoc executable in /usr/local/bin and the google folder in /usr/local/include. When I try running my program, I get this error

/usr/local/bin/protoc: 1: /usr/local/bin/protoc: Syntax error: "(" unexpected

What am I doing wrong? What can I do to get my program working correctly? My program is somewhat similar to the example code in C++. I have also tested using the example code given and the same problem occurs.

I am obtaining the protoc executable and the google folder from "protoc-3.3.0-linux-x86_32.zip". I am working on a Raspberry Pi 3 Model B.

Phlip79 avatar Jun 13 '17 14:06 Phlip79

How did you invoke protoc? And how does your .proto file look like?

xfxyjwf avatar Jun 13 '17 17:06 xfxyjwf

I am calling protoc by calling make in the examples folder. My .proto file is also the same one from the examples folder. I am now just trying to get the example working. I am starting with a new machine, copying the "examples" folder over, then putting the protoc executable in /usr/local/bin and the google folder in /usr/local/include.

I wish to just use the examples add_person_cpp and list_people_cpp for now, without having to download and run the whole protobuf library.

Phlip79 avatar Jun 13 '17 17:06 Phlip79

Can you try this in the examples directory and report back what you get:

protoc --cpp_out=. addressbook.proto

xfxyjwf avatar Jun 13 '17 17:06 xfxyjwf

bash: /usr/local/bin/protoc: cannot execute binary file: Exec format error

What could this mean?

Phlip79 avatar Jun 13 '17 18:06 Phlip79

It means the protoc binary you downloaded is not the correct format for your system. Try:

$ file /usr/local/bin/protoc
$ uname -a

The above 2 commands should show you the type of the binary you downloaded and the info of your operating system.

It seems you are using C++. I suggest you build the protobuf library from source code. It's actually quite easy. Just download https://github.com/google/protobuf/releases/download/v3.3.0/protobuf-cpp-3.3.0.tar.gz, extract it and run ./configure && make && sudo make install. It should only take a couple of minutes.

xfxyjwf avatar Jun 13 '17 18:06 xfxyjwf

On a Raspberry Pi, running make takes at least 45 minutes. I want to be able to distribute it without everyone having to run make. I am currently running armv7l, which is a 32-bit system. I have also downloaded the 32-bit version of protoc. I have tried using the protoc that I created on a previous version by running make on the Raspberry Pi and that also has the same error.

Phlip79 avatar Jun 13 '17 18:06 Phlip79

The protoc binary we put up on the release page is for x86/x64 only. For arm you have to build it from source code. I think you can build it once and store/distribute the binary you build for others to use. Cross-compiling may also be an option.

xfxyjwf avatar Jun 13 '17 18:06 xfxyjwf

I have used the same protoc and now I get a different error.

protoc: error while loading shared libraries: libprotobuf.so.13: cannot open shared object file: No such file or directory

libprotobuf.so.13 is a linker to libprotobuf.so.13.0.0, where both files are in /usr/local/lib. Where is it looking for this file?

Phlip79 avatar Jun 13 '17 18:06 Phlip79

So you are using the protoc binary and protobuf library you built from source code? Try if "sudo ldconfig" helps.

xfxyjwf avatar Jun 13 '17 19:06 xfxyjwf

I have tried that

Phlip79 avatar Jun 13 '17 19:06 Phlip79

See: https://stackoverflow.com/questions/25518701/protobuf-cannot-find-shared-libraries

xfxyjwf avatar Jun 13 '17 19:06 xfxyjwf

It worked!!! Thank you very much. You have been extremely helpful.

In the end I was copying over "libprotobuf.so.13". This created an error because "sudo ldconfig" is suppose to create this file based off of "libprotobuf.so.13.0.0".

Phlip79 avatar Jun 13 '17 19:06 Phlip79