谷歌协议缓冲区交叉编译
我使用Google协议缓冲区的问题有两个部分,一个是关于编译器选项,另一个是交叉编译。构建机器是Power6,64位;主机是PowerPC450,32位。海湾合作委员会 4.1.2。
第一个问题是关于编译器选项:
我试图在需要交叉编译的 PowerPC 机器上安装 Google 协议缓冲区。构建机器是Power6,64位;主机是PowerPC450,32位。 首先,我尝试直接在构建机器上安装,并使用选项告诉编译器使用哪个:
./configure --prefix=/home/where_to_install --host=powerpc-bgp-linux
然后 make,make check,make install,一切都很好。我认为我已经指定了主机,它应该包含编译需要知道的足够信息。 当我尝试编译我的代码时,
/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 中变量的大量错误。
我知道这是因为编译器无法识别选项 -zmuldefs 因此无法找到确实存在的文件 common.h 。我用谷歌搜索了一下,没有得到任何明确的想法。如何使编译器可以使用该选项或可以找到该文件?还是我的编译命令有问题?
第二个问题是关于交叉编译的。 Google协议缓冲区的自述文件并不清楚到底如何交叉编译。它说我必须使用 --with-protoc=protoc 来告诉配置使用哪个,好的,但在此之前我必须为主机安装一个副本。我首先使用该命令为主机安装一个副本,
./configure --prefix=/home/where_to_install/built --host=powerpc-bgp-linux
然后进行 make、make install。
然后使用下面的交叉编译器使用与主机相同的编译器:
./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
然后 make 并得到错误:
大量编译信息 ...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协议缓冲区?我没有找到任何关于此的详细示例。
非常感谢,
-托尼
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将尝试回答你的第二个问题:
当我交叉编译 protobuf 库时,我首先将它安装在我的主机上。这相对简单:
那么您应该让它在您的构建机器上运行。不要忘记
事后执行此操作,否则此编译中的工件将干扰下一个构建。
现在,我通过配置为我的另一台机器(在构建机器上)构建它
然后执行通常的 make、make check 和 make install,并且您需要复制到另一台机器的文件位于 /patch/to/built/files 中。
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:
Then you should have it running on your build machine. Don't forget to do a
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
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.
对于第一个问题,在编译并安装 protobuf 库后,
您需要使用 -I 标志将 /your_dir/include 下的包含路径添加到 makefile 中,例如
。
For the first question, after you compiled and installed protobuf library with
You need add the include path under /your_dir/include to your makefile with -I flag, for example
.