Google协议缓冲区交叉编译 [英] Google protocol buffers cross compiling
问题描述
我使用Google协议缓冲区的问题有两个部分,一个是关于编译器选项,另一个是交叉编译.构建机器是Power6、64位;主机是32位的PowerPC450.Gcc 4.1.2.
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:
我正在尝试在需要交叉编译的PowerPC机器上安装Google协议缓冲区.构建机器是Power6、64位;主机是32位的PowerPC450.首先,我尝试直接在构建机器上安装,并带有告诉编译器要使用的选项:
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
我得到了错误:
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
并没有发现关于common.h变量的很多错误.
and a lot of error about variables in common.h were not found.
我知道这是因为编译器无法识别-zmuldefs选项,因此找不到存在的common.h文件.我用Google搜索,但没有任何明确的主意.如何使编译器可以使用该选项或可以找到文件?还是我的编译命令有问题?
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?
第二个问题是关于交叉编译.Google协议缓冲区的自述文件尚不清楚如何交叉编译.它说我必须使用--with-protoc = protoc来告诉configure使用哪个,好,但是在此之前,我必须为主机安装一个副本.我首先使用命令为主机安装副本
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 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
然后制造并得到错误:
很多编译信息... blabla .....
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
我在哪里做错了?我还尝试在第一次安装(对于主机)中使用指定的编译器,它得到了与上面第二次安装相同的错误.成功完成安装后,这里将有两个安装,应该使用哪个安装?有没有人能给我一个例子,说明我可以如何交叉编译Google协议缓冲区?我没有找到任何有关此的详细示例.
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.
非常感谢
-托尼
推荐答案
我将尝试回答您的第二个问题:
I'm going to try to answer your second question:
当我交叉编译protobuf库时,我首先将其安装在主机上.这是相对简单的:
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
然后执行通常的制作,制作检查和安装,您需要复制到其他计算机上的文件位于/patch/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.
这篇关于Google协议缓冲区交叉编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!