I need to cross-compile some C/C++ library. The library depends on several C/C++ libraries. Some of those of libraries in turn depend on other libraries. All libraries come with configure script. I know how to compile and install libraries on host system – install dependencies before the lib I need. Obviously this won't work when cross-compiling. Any tips are appreciated. Thank you.
Generally, to cross-compile an autotooled package, you pass a couple of extra arguments to ./configure
: --host
and --build
. --host
is the name of the system that the built programs will run on, and --build
is the name of the system that does the compiling.
When I say "name of the system", I mean a tuple of the form ARCH-VENDOR-OS-LIBC
. (For example i686-pc-linux-gnu
is the tuple describing the system I'm currently using.) Sometimes parts of the tuple are elided, as in the case of the mingw32 toolchain (on my system, the mingw32 cross tools are installed with the tuple i586-mingw32msvc
and/or amd64-mingw32msvc
).
(There's another argument to configure, --target
, which is for cross-compiling compilers and specifies the system that the compiler being built will target when generating code.)
Each toolchain has its own subdirectory under /usr
such as /usr/i586-mingw32msvc
. You're going to want to install new packages here so they get found. Use the --prefix
argument to configure
.
So to cross-compile from my GNU/Linux system to a MinGW32 system, I would run configure
like this:
./configure --host=i586-mingw32msvc --build=i686-pc-linux-gnu --prefix=/usr/i586-mingw32msvc
So start with the leaves of your dependency graph and work your way up. You may want to also pass --enable-static --disable-shared
to configure
: that will stop the creation of dynamic libraries for libtooled packages. You may have to install some packages natively as well as cross-compiling them, if a package needs to run a program as part of the build.
Sometimes configure
's tests will fail: where it tries to compile and run a program, for instance. Often these tests set a cache variable which you can also pass on the command line to configure
. Similarly, you can override things like program paths and library compile/link flags. Check your package's ./configure --help
.