Cross Compiling Protobuf For Raspberry Pi

1,989 views
Skip to first unread message

Andrew Capodieci

unread,
Nov 13, 2014, 8:57:59 AM11/13/14
to prot...@googlegroups.com
I'm trying to cross compile google Protocol buffers for the Raspberry Pi, so I can cross compile my own software which links to protobuf.

I've installed protobuf-2.6.0 to the directory ~/ExternalLibs/protobuf-2.6.0, where I perform the following steps:

    cd ~/ExternalLibs/protobuf-2.6.0
   
./configure --disable-shared
    make
    make check

 -- all (5/5) tests pass

    sudo make install
    make distclean

This should set up the initial protoc executable that can be run by my build machine (Lenovo w540 laptop running Ubuntu 12.04) during the cross compiling for my host, the raspberry pi.

I then run:

    ./configure --host=arm-linux-gnueabi CC=/opt/cross/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc CXX=/opt/cross/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-g++ --with-protoc=/usr/bin/protoc --prefix=/home/andrewc1204/raspberrypi_crosscompile/protobuf_xtools/

My cross compiler was built following this tutorial: http://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/. The only extra thing I did was enable an additional c++ compiler on top of building the c compiler in the ct-ng menus, which is why I'm able to use the g++ compiler on top of the gcc compiler.

This ./configure seems to run, and then I call
   
    make

The output is as follows:

   
make  all-recursive
    make
[1]: Entering directory `/home/andrewc1204/ExternalLibs/protobuf-2.6.0'
    Making all in .
    make[2]: Entering directory `
/home/andrewc1204/ExternalLibs/protobuf-2.6.0'
    make[2]: Leaving directory `/home/andrewc1204/ExternalLibs/protobuf-2.6.0'

   
Making all in src
    make
[2]: Entering directory `/home/andrewc1204/ExternalLibs/protobuf-2.6.0/src'
    /usr/bin/protoc -I. --cpp_out=. google/protobuf/unittest.proto google/protobuf/unittest_empty.proto google/protobuf/unittest_import.proto google/protobuf/unittest_import_public.proto google/protobuf/unittest_mset.proto google/protobuf/unittest_optimize_for.proto google/protobuf/unittest_embed_optimize_for.proto google/protobuf/unittest_custom_options.proto google/protobuf/unittest_lite.proto google/protobuf/unittest_import_lite.proto google/protobuf/unittest_import_public_lite.proto google/protobuf/unittest_lite_imports_nonlite.proto google/protobuf/unittest_no_generic_services.proto google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto
    google/protobuf/unittest.proto:173:3: Expected "required", "optional", or "repeated".
    google/protobuf/unittest.proto:173:21: Missing field number.
    google/protobuf/unittest.proto:610:3: Expected "required", "optional", or "repeated".
    google/protobuf/unittest.proto:610:13: Missing field number.
    google/protobuf/unittest.proto:632:3: Expected "required", "optional", or "repeated".
    google/protobuf/unittest.proto:632:13: Missing field number.
    google/protobuf/unittest.proto:647:3: Expected "required", "optional", or "repeated".
    google/protobuf/unittest.proto:647:13: Missing field number.
    google/protobuf/unittest.proto:672:3: Expected "required", "optional", or "repeated".
    google/protobuf/unittest.proto:672:13: Missing field number.
    google/protobuf/unittest.proto:853:1: Expected "required", "optional", or "repeated".
    google/protobuf/unittest.proto:853:21: Missing field number.
    google/protobuf/unittest.proto:862:1: Reached end of input in message definition (missing '}').
    make[2]: *** [unittest_proto_middleman] Error 1
    make[2]: Leaving directory `
/home/andrewc1204/ExternalLibs/protobuf-2.6.0/src'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/home/andrewc1204/ExternalLibs/protobuf-2.6.0'

    make
: *** [all] Error 2

I'm stuck at this point, and don't know what else to check to try and debug this problem. Any help is greatly appreciated! Please let me know if any additional information is helpful and I will gladly supply it.

Feng Xiao

unread,
Nov 13, 2014, 1:52:22 PM11/13/14
to Andrew Capodieci, Protocol Buffers
On Thu, Nov 13, 2014 at 5:57 AM, Andrew Capodieci <andrew.c...@gmail.com> wrote:
I'm trying to cross compile google Protocol buffers for the Raspberry Pi, so I can cross compile my own software which links to protobuf.

I've installed protobuf-2.6.0 to the directory ~/ExternalLibs/protobuf-2.6.0, where I perform the following steps:

    cd ~/ExternalLibs/protobuf-2.6.0
   
./configure --disable-shared
    make
    make check

 -- all (5/5) tests pass

    sudo make install
    make distclean

This should set up the initial protoc executable that can be run by my build machine (Lenovo w540 laptop running Ubuntu 12.04) during the cross compiling for my host, the raspberry pi.

I then run:

    ./configure --host=arm-linux-gnueabi CC=/opt/cross/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc CXX=/opt/cross/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-g++ --with-protoc=/usr/bin/protoc --prefix=/home/andrewc1204/raspberrypi_crosscompile/protobuf_xtools/

"make install" will install the protoc in /usr/local/bin by default, so you need to use --with-protoc=/usr/local/bin/protoc here. You can check "/usr/bin/protoc --version" to see whether it's version 2.6.0.
 

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Andrew Capodieci

unread,
Nov 13, 2014, 4:30:34 PM11/13/14
to prot...@googlegroups.com
I took a look at the specific lines for the errors, and the /usr/bin/protoc I built for the build machine is having issues on the following lines:

172   // For oneof test
173   oneof oneof_field {
174     uint32 oneof_uint32 = 111;
175     NestedMessage oneof_nested_message = 112;
176     string oneof_string = 113;
177     bytes oneof_bytes = 114;
178   }

// Test oneofs.
609 message TestOneof {
610   oneof foo {
611     int32 foo_int = 1;
612     string foo_string = 2;
613     TestAllTypes foo_message = 3;
614     group FooGroup = 4 {
615       optional int32 a = 5;
616       optional string b = 6;
617     }
618   }
619 }

631 message TestOneof2 {
632   oneof foo {
633     int32 foo_int = 1;
634     string foo_string = 2;
635     string foo_cord = 3 [ctype=CORD];
636     string foo_string_piece = 4 [ctype=STRING_PIECE];
637     bytes foo_bytes = 5;
638     NestedEnum foo_enum = 6;
639     NestedMessage foo_message = 7;
640     group FooGroup = 8 {
641       optional int32 a = 9;
642       optional string b = 10;
643     }
644     NestedMessage foo_lazy_message = 11 [lazy=true];
645   }
646
647   oneof bar {
648     int32 bar_int = 12 [default = 5];
649     string bar_string = 13 [default = "STRING"];
650     string bar_cord = 14 [ctype=CORD, default = "CORD"];
651     string bar_string_piece = 15 [ctype=STRING_PIECE, default = "SPIECE"];
652     bytes bar_bytes = 16 [default = "BYTES"];
653     NestedEnum bar_enum = 17 [default = BAR];
654   }

671 message TestRequiredOneof {
672   oneof foo {
673     int32 foo_int = 1;
674     string foo_string = 2;
675     NestedMessage foo_message = 3;
676   }
677   message NestedMessage {
678     required double required_double = 1;
679   }
680 }

853 service TestService {
854   rpc Foo(FooRequest) returns (FooResponse);
855   rpc Bar(BarRequest) returns (BarResponse);
856 }

Andrew Capodieci

unread,
Nov 13, 2014, 4:52:42 PM11/13/14
to prot...@googlegroups.com, andrew.c...@gmail.com
You're absolutely right Feng, thanks! I had a protoc version 2.4.0 in /usr/bin somehow, and I have a protoc version 2.6.0 in /usr/local/bin. Now I have an issue with the make check step, where it has a problem executing a binary file for all 4 tests, as can be seen in the attached log file.
make_check.log

Andrew Capodieci

unread,
Nov 13, 2014, 5:04:24 PM11/13/14
to prot...@googlegroups.com, andrew.c...@gmail.com
I guess I don't understand what the make check is doing...is it trying to run tests using the library it just cross compiled for the raspberry pi, and thus it's trying to run a library built for arm on a linux machine and thus failing to execute?

Feng Xiao

unread,
Nov 13, 2014, 5:36:02 PM11/13/14
to Andrew Capodieci, Protocol Buffers
On Thu, Nov 13, 2014 at 2:04 PM, Andrew Capodieci <andrew.c...@gmail.com> wrote:
I guess I don't understand what the make check is doing...is it trying to run tests using the library it just cross compiled for the raspberry pi, and thus it's trying to run a library built for arm on a linux machine and thus failing to execute?
Yes. I guess "make check" doesn't make sense when you cross-compile.
Reply all
Reply to author
Forward
0 new messages