title: Google protocol buffers cross compiling
body: <p>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.</p>
  
  <p>First problem is about compiler options:</p>
  
  <p>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:</p>
  
  <pre><code>./configure --prefix=/home/where_to_install --host=powerpc-bgp-linux
  </code></pre>
  
  <p>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</p>
  
  <pre><code>/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
  </code></pre>
  
  <p>I was given error:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>and a lot of error about variables in common.h were not found. </p>
  
  <p>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?</p>
  
  <hr>
  
  <p>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</p>
  
  <pre><code>./configure --prefix=/home/where_to_install/built --host=powerpc-bgp-linux
  </code></pre>
  
  <p>then make, make install.</p>
  
  <p>Then cross compile with below which uses same compiler as host machine uses:</p>
  
  <pre><code>./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
  </code></pre>
  
  <p>Then make and got error:</p>
  
  <p>a lot of compiling info ...blabla.....</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>Thanks a lot,</p>
  
  <p>-Tony</p>