Cross compilation

Jonathan Wakely
Fri Nov 10 23:03:00 GMT 2017

On 10 November 2017 at 21:09, Kai Ruottu <> wrote:
> Kai Ruottu kirjoitti 10.11.2017 klo 18:14:
>> Kai Ruottu kirjoitti 10.11.2017 klo 11:21:
>>> 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).
>> ../../../../libstdc++-v3/libsupc++/ In function 'void*
>> aligned_alloc(std::size_t, std::size_t)':
>> ../../../../libstdc++-v3/libsupc++/ error: 'void*
>> aligned_alloc(std::size_t, std::size_t)' was declared 'extern' and later
>> 'static' [-fpermissive]
>>  aligned_alloc (std::size_t al, std::size_t sz)
>>  ^~~~~~~~~~~~~
>> In file included from
>> /home/src-old/gcc-7.2.0/build/x86_64-freebsd11.1/libstdc++-v3/include/cstdlib:75:0,
>>                  from
>> /home/src-old/gcc-7.2.0/build/x86_64-freebsd11.1/libstdc++-v3/include/stdlib.h:36,
>>                  from ../../../../libstdc++-v3/libsupc++/
>> /home/src-old/gcc-7.2.0/build/gcc/include-fixed/stdlib.h:178:8: note:
>> previous declaration of 'void* aligned_alloc(size_t, size_t)'
>>  void * aligned_alloc(size_t, size_t) __malloc_like __alloc_align(1)
>>         ^~~~~~~~~~~~~
>> make[4]: *** [new_opa.lo] Virhe 1
>> make[4]: Poistutaan hakemistosta
>> "/home/src-old/gcc-7.2.0/build/x86_64-freebsd11.1/libstdc++-v3/libsupc++"
>> make[3]: *** [all-recursive] Virhe 1
>> Seemingly the same problem was with the x86_64-freebsd10.1 target which I
>> tried first after updating the
>> earlier gcc-4.9.2 to gcc-4.9.3 with it. No problems in that build. Will
>> check the FreeBSD 11.1 with gcc-4.9.3
>> too...
> Yes, just the same error came with gcc-7.2.0 sources and FreeBSD 10.1
> target. But builds with gcc-4.9.3,
> gcc-5.3.0 and gcc-6.3.0 sources worked OK for FreeBSD 11.1 target.
> Unfortunately my C++ skills are rusty so
> I cannot tell what to fix in this issue with gcc-7.2.0 :(

No C++ is needed. That function is only declared when #if

Why does autoconf test say that FreeBSD doesn't have aligned_alloc, if
it does have it?

The test is done by:

  AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc)

Maybe that test checks for the function using -std=c++98, so the C11
function isn't defined? Check the config.log to see what happened when
testing for that function.

If FreeBSD defines it, we need to detect that, and use the FreeBSD
version, not the static version defined in

(It's possible FreeBSD has always defined it, but only GCC 7.2 gives
an error for the mismatched static/extern, but that isn't really
important -- either way we should use the OS version if it exists)

More information about the Gcc-help mailing list