0

I need to cross-compile google protobuf libraries from its source at https://github.com/protocolbuffers/protobuf/tree/v3.14.0

To compile it for my host, I do this:

mkdir /path/to/protobuf && cd /path/to/protobuf
git clone https://github.com/protocolbuffers/protobuf.git ./
git checkout v3.14.0
git submodule update --init --recursive
./autogen.sh
./configure "CFLAGS=-fPIC" "CXXFLAGS=-fPIC" --prefix=/out/x86_64
make
make install

I more or less understand that process for host (x86_64) builds, but what more do I need to specify to cross-compile (to arm_64)?

I have vague awareness that I need to specify the cross-toolchain to the configure script, maybe something like:

./configure "CFLAGS=-fPIC" "CXXFLAGS=-fPIC" --prefix=/out/arm_64 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++

?

But what I've always been unclear of when cross-compiling with this "configure; make; make install" recipe is: are specifying CC and CXX sufficient? If so, why? I.e. isn't there a possibility the make recipe might run ar or ld or something else in the cross-toolchain? I think the crux of my question is: what's the full set of arguments I need to specify to configure to cross-compile? (Specifically to arm_64, but also in general).

Though this question focuses on cross-compiling protobuf, I'd like to understand if there's a prevailing convention that applies to all projects that use the "configure; make; make install" recipe.


What I've tried: Read Google protocol buffers cross compiling, but I believe my question is different, because that asker has already specified the CC and CXX flags, the answers do not seem to discuss other flags, and my

StoneThrow
  • 5,314
  • 4
  • 44
  • 86

1 Answers1

0

The --host and --build options are usually all we need for cross-compiling.
https://www.gnu.org/software/automake/manual/html_node/Cross_002dCompilation.html

--host=host-type
the type of system on which the package runs. By default it is the same as the build machine. The tools that get used to build and manipulate binaries will, by default, all be prefixed with host-type-, such as host-type-gcc, host-type-g++, host-type-ar, and host-type-nm.
https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.70/html_node/Specifying-Target-Triplets.html#Specifying-Names

So it looks like one can do:

./configure "CFLAGS=-fPIC" "CXXFLAGS=-fPIC" --prefix=/out/arm_64 --host=aarch64-linux-gnu

That worked for me, for my immediate protobuf-related needs, and the verbiage, to me, says that this is the general convention also: a more comprehensive option than specifying CC and CXX and whatever other crosstool wrapper variables.

StoneThrow
  • 5,314
  • 4
  • 44
  • 86