Google protocol buffers cross compiling
Asked Answered
A

2

7

My problems of using Google protocol buffers has two parts, one is about compiler options, another is cross compiling. The build machine is a Power6, 64bit; host machine is a PowerPC450, 32bit. Gcc 4.1.2.

First problem is about compiler options:

I'm trying to install Google protocol buffers on a PowerPC machine which requires cross compiling. The build machine is a Power6, 64bit; host machine is a PowerPC450, 32bit. Firstly I tried to install on the build machine directly, with options to tell compiler which to use:

./configure --prefix=/home/where_to_install --host=powerpc-bgp-linux

Then make, make check, make install, everything's fine. I think that I've specified the host machine, that should include enough information that compile need to know. When I try to compile my code with

/bgsys/drivers/ppcfloor/gnu-linux/powerpc-bgp-linux/bin/g++ -g -zmuldefs -Xlinker -I/home/somewhere_installed/include $sourceFile -o $fileName -L/home/somewhere_installed/lib -lz -lstdc++ -lrt -lpthread -lm -lc -lprotobuf -lprotoc msg.pb.cc

I was given error:

g++: unrecognized option '-zmuldefs'
In file included from zht_util.h:20,
                 from hash-phm.cpp:9:
meta.pb.h:9:42: error: google/protobuf/stubs/common.h: No such file or directory

and a lot of error about variables in common.h were not found.

I know it's because the compiler doesn't recognize the option -zmuldefs so can't find the file common.h which does exist. I Googled it and didn't get any clear idea. How can I make the complier can use the option or can find the file? Or is any problem in my compiling command?


The second problem is about cross compiling. The readme file of Google protocol buffers is not clear about how exactly cross compile. It said I must use --with-protoc=protoc to tell configure which to use, OK, but before that I have to install a copy for host machine. I use the command first to install a copy for host

./configure --prefix=/home/where_to_install/built --host=powerpc-bgp-linux

then make, make install.

Then cross compile with below which uses same compiler as host machine uses:

./configure --prefix=/home/tonglin/Installed/built_3 CC=/bgsys/drivers/ppcfloor/gnu-linux/bin/powerpc-bgp-linux-gcc CXX=/bgsys/drivers/ppcfloor/gnu-linux/bin/powerpc-bgp-linux-g++ --host=powerpc-bgp-linux --with-protoc=/home/where_already_Installed/built/bin/protoc

Then make and got error:

a lot of compiling info ...blabla.....

collect2: ld returned 1 exit status
make[3]: *** [protoc] Error 1
make[3]: Leaving directory `/gpfs/home/somewere/src/protobuf-2.4.1/src'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/gpfs/home/somewere/src/protobuf-2.4.1/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/gpfs/home/tonglin/Installed/src/protobuf-2.4.1'
make: *** [all] Error 2

Where did I do wrong? I also tried with the specified compiler in the first installing(for host), it got same error as second install did above. Once I succeed to finish installations, here I will have two installs, which should I use? Is there any one can give me an example of how exactly can I cross compile Google protocol buffers? I didn't find any detailed example about this.

Thanks a lot,

-Tony

Arvad answered 27/12, 2011 at 17:58 Comment(1)
I'm having similar issue...I'm integrating ProtoBuf lib in Android Project via JNI Layer. I'm following tutorial CPP_ProtoBuf, but while compiling it produce similar error. jni/./mysense/wrapper/addressbook.pb.h:9:42: fatal error: google/protobuf/stubs/common.h: No such file or director. Any suggestion here?Regionalism
R
6

I'm going to try to answer your second question:

When I cross-compiled the protobuf library I first installed it on my host machine. This is relatively straightforward:

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

Then you should have it running on your build machine. Don't forget to do a

make distclean

afterwards or artifacts from this compilation will interfere with the next build.

Now I build it for my other machine (on the build machine) by configuring with

./configure --host=ppc CC=powerpc-none-linux-gnuspe-gcc CXX=powerpc-none-linux-gnuspe-g++ --with-protoc=protoc --prefix=/path/to/built/files

Then do the usual make, make check and make install and the files you need to copy to your other machine are in /patch/to/built/files.

Rosenberry answered 29/12, 2011 at 18:5 Comment(9)
thanks for your answer, but I don't have direct access to the host machines although they share hard drives with build machine, so I can't install any thing on them directly. What I can do is cross compiling it and install the host version on a build machine. Any other solution than installing on host machine?Arvad
I don't quite understand. So you have access to your build machine, but not to your host machine? Then how do you run programs on your host machine? If you can run stuff on that machine, you could install everything on the shared drives and run them there.Rosenberry
Yes, that's a big machine. I can only access the head node which is the build machine, and I can use the work nodes(host machine) by using Cobalt scripts. Shell is not supported on work nodes.Arvad
Hm ok. So installing the protobuf library on your build machine works? Then you do a make distclean and then you configure with the prefix pointing to the final destination for the cross-compiled library? And then make fails?Rosenberry
Yes it fails to make. Do you mean without option "--with-protoc"?Arvad
No, with the option "--with-protoc" that option is actually only there to tell the cross-compiled version to use an already existing version of protoc to run tests on.Rosenberry
I did with and without "--with-protoc" and was given the same error shown in the original post.Arvad
Hm, that's weird. And you did make distclean between the two builds? Could you add the linking errors to your question above? There might be a clue in there..Rosenberry
make check is not necessary for cross-compilation because it will try to run cross-compiled binary and you will get a failRomanticist
A
0

For the first question, after you compiled and installed protobuf library with

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

You need add the include path under /your_dir/include to your makefile with -I flag, for example

-I/your_dir/include

.

Arvad answered 8/4, 2014 at 0:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.