Hosted GCC Cross-Compiler: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
(Updated for a later version of GCC)
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
Line 38:
Your previous <tt>i686-elf</tt> toolchain was built using the <tt>--without-headers</tt> configure option. This tells the compiler that there is no standard library and no headers. The libgcc is built with libc support as described above. This requires the standard library headers to be installed into your [[Meaty Skeleton#System Root|system root]] prior to the cross-compiler build.
 
<sourcesyntaxhighlight lang="bash">
cd $HOME/myos
mkdir -p sysroot
Line 44:
cp -RT libc/include sysroot/usr/include
cp -RT kernel/include sysroot/usr/include
</syntaxhighlight>
</source>
 
'''Note''': Not all <tt>cp(1)</tt> implementations support the <tt>-RT</tt> combination that conveniently merges the contents of one directory into another.
Line 50:
== Binutils ==
 
<sourcesyntaxhighlight lang="bash">
cd $HOME/src
mkdir build-binutils
Line 57:
make
make install
</syntaxhighlight>
</source>
 
'''--with-sysroot=''' This option tells the compiler where your sysroot is. It is not used during the compilation process, but it is remembered and used when the linker searches for libraries.
Line 63:
== GCC ==
 
<sourcesyntaxhighlight lang="bash">
cd $HOME/src
mkdir build-gcc
Line 70:
make all-gcc all-target-libgcc
make install-gcc install-target-libgcc
</syntaxhighlight>
</source>
 
'''--with-sysroot=''' This option tells the compiler where your sysroot is. It is used during the libgcc build and is remembered and used when the compiler searches for headers and libraries.
Line 82:
The libstdc++ library was still not built above as it depends on libc as it needs to perform link tests to know about it. The GCC developers have poorly designed the libstdc++ package and it is tied to GCC and must be built as part of GCC, it can't be built on its own without tricks. If you saved your build-gcc directory from earlier, you can continue the process now (otherwise, it will build a full new cross-compiler for no good reason):
 
<sourcesyntaxhighlight lang="bash">
cd $HOME/src/build-gcc
make all-target-libstdc++-v3
make install-target-libstdc++-v3
</syntaxhighlight>
</source>
 
=== Troubleshooting ===
In case you get an this error (occurs when using newlib):
 
<sourcesyntaxhighlight lang="bash">
./../../../gcc-11.3.0/libstdc++-v3/libsupc++/new_opa.cc:62:1: 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)
</syntaxhighlight>
</source>
 
Open the file '''libstdc++-v3/libsupc++/new_opa.cc''' with an editor and remove the "static inline" before in the function prototype.