简体   繁体   English

Google协议缓冲区交叉编译

[英]Google protocol buffers cross compiling

My problems of using Google protocol buffers has two parts, one is about compiler options, another is cross compiling. 我使用Google协议缓冲区的问题有两个部分,一个是关于编译器选项,另一个是交叉编译。 The build machine is a Power6, 64bit; 构建机器是64位Power6; host machine is a PowerPC450, 32bit. 主机是32位的PowerPC450。 Gcc 4.1.2. 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. 我正在尝试在需要交叉编译的PowerPC机器上安装Google协议缓冲区。 The build machine is a Power6, 64bit; 构建机器是64位Power6; host machine is a PowerPC450, 32bit. 主机是32位的PowerPC450。 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. 并没有发现关于common.h变量的很多错误。

I know it's because the compiler doesn't recognize the option -zmuldefs so can't find the file common.h which does exist. 我知道这是因为编译器无法识别-zmuldefs选项,因此找不到存在的common.h文件。 I Googled it and didn't get any clear idea. 我用Google搜索,但没有任何明确的主意。 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. Google协议缓冲区的自述文件尚不清楚如何交叉编译。 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. 它说我必须使用--with-protoc = protoc来告诉configure使用哪个,好,但是在此之前,我必须为主机安装一个副本。 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: 然后make并得到错误:

a lot of compiling info ...blabla..... 很多编译信息... 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? 有没有人可以举一个例子说明我如何交叉编译Google协议缓冲区? I didn't find any detailed example about this. 我没有找到任何有关此的详细示例。

Thanks a lot, 非常感谢,

-Tony -托尼

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. 当我交叉编译protobuf库时,我首先将其安装在主机上。 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. 然后执行通常的制作,检查和安装,您需要复制到其他计算机上的文件位于/ patch / to / built / files中。

For the first question, after you compiled and installed protobuf library with 对于第一个问题,使用以下命令编译并安装protobuf库后

./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下的include路径添加到makefile中。

-I/your_dir/include

.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM