This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Cross compilation


RAVI DEWANGAN kirjoitti 10.11.2017 klo 4:56:
Hi GNU Team,

Could you please guide me regarding cross compilation.

I am trying to cross compile the toolchain for FreeBSD11(target) using
Ubuntu16.04(host).

The issue is
/home/rdewangan/freebsd/gcc-7.2.0/build/./gcc/xgcc
-B/home/rdewangan/freebsd/gcc-7.2.0/build/./gcc/
-B/opt/freebsd_toolchain/x86_64-pc-freebsd11/bin/
-B/opt/freebsd_toolchain/x86_64-pc-freebsd11/lib/ -isystem
/opt/freebsd_toolchain/x86_64-pc-freebsd11/include -isystem
/opt/freebsd_toolchain/x86_64-pc-freebsd11/sys-include    -g -O2 -O2  -g
-O2 -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -W -Wall -Wno-narrowing
-Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes
-Wold-style-definition  -isystem ./include   -fpic -pthread -g -DIN_LIBGCC2
-fbuilding-libgcc -fno-stack-protector -Dinhibit_libc  -fpic -pthread -I.
-I. -I../.././gcc -I../../../libgcc -I../../../libgcc/.
-I../../../libgcc/../gcc -I../../../libgcc/../include  -DHAVE_CC_TLS  -o
_muldi3.o -MT _muldi3.o -MD -MP -MF _muldi3.dep -DL_muldi3 -c
../../../libgcc/libgcc2.c -fvisibility=hidden -DHIDE_EXPORTS
In file included from ../../../libgcc/../gcc/tsystem.h:44:0,
                  from ../../../libgcc/libgcc2.c:27:
/home/rdewangan/freebsd/gcc-7.2.0/build/gcc/include/stddef.h:56:10: fatal
error: sys/_types.h: No such file or directory
  #include <sys/_types.h>
           ^~~~~~~~~~~~~~
compilation terminated.
Makefile:491: recipe for target '_muldi3.o' failed

For a "working compiler" one needs also the target C library. Prebuilt and pretested in your case when your FreeBSD system is already made.  There isn't much difference between a native and a cross compiler in this issue, both require the target C library during the GCC build when the extra libraries : libgcc, libstdc++, libssp etc will be built.

A cross compiler needs also the binutils made for the "host-to-target" use but a native build usually already has also them prebuilt, sometimes as non-GNU "native ones".

Furthermore the target C library must be put into a separate $SYSROOT on the host. Not in it's "native" place (usually '/lib*', '/usr/include' and '/usr/lib*' like in Linux) but in a sysroot like '/opt/freebsd_toolchain/sysroot' in your case, the native FreeBSD
sysroot '/' being replaced with this.

As you can see, you already have the cross compiler binaries made. Those which run on your Linux host : the '/home/rdewangan/freebsd/gcc-7.2.0/build/./gcc/xgcc' is the compiler driver ("x86_64-pc-freebsd11-gcc" after its installation), the "cc1", "cc1plus" etc. also in the '/home/rdewangan/freebsd/gcc-7.2.0/build/gcc'.  But after this the new GCC needs the target C library stuff like its headers when compiling 'libgcc' etc for the
target.

  1283  sudo ../configure --without-headers --with-gnu-as --with-gnu-ld
--enable-languages=c,c++ --disable-nls --enable-libssp --enable-gold
--enable-ld --target=x86_64-pc-freebsd11 --prefix=/opt/freebsd_toolchain
--with-gmp=/opt/freebsd_toolchain --with-mpc=/opt/freebsd_toolchain
--with-mpfr=/opt/freebsd_toolchain --disable-libgomp
  1284  sudo LD_LIBRARY_PATH=/opt/freebsd_toolchain/lib make

A configure like this could be enough for making a "kernel compiler", for compiling an Unix or Linux kernel from its sources. But not user-level libraries and applications.

The target C libraries used to be inside the FreeBSD install packages, 'base.txz' and 'lib32.txz' or something. You must unpack them into some temporary place and copy
the needed parts from there into your chosen $SYSROOT. Or copy them from the
installed target system.  Then in the binutils and GCC configure use the :
--with-sysroot=$SYSROOT
to tell where the target C library stuff is....


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]