[llvm-dev] Cross compiling C++ program

Jonathan Roelofs via llvm-dev llvm-dev at lists.llvm.org
Mon Aug 7 08:59:11 PDT 2017



On 8/5/17 3:47 PM, Goran Mekić via llvm-dev wrote:

> 
> # set -xg CC /tmp/barearm-sysroot/bin/clang-6.0
> # set -xg CXX /tmp/barearm-sysroot/bin/clang-6.0

So I think I need to clarify what a sysroot actually is, since that ^ 
suggests you think it's like $prefix, which it's not.

A sysroot is a collection of headers, and runtime bits, all of which are 
designed to run on a $target. Your clang however, was built to run on 
$host. For non-baremetal targets, the headers & libraries are a snapshot 
of how they'd be laid out on the actual target, i.e. if your target has 
`/usr/lib/libc.a`, then your sysroot should have 
`$sysroot/usr/lib/libc.a`. Likewise for all the relevant headers, and 
$target binaries.

Usually, when you build a packaged toolchain, the sysroots live inside 
$prefix next to the compiler installation like so:

$prefix/armv7em-none-eabi/usr/include/stdio.h
$prefix/armv7em-none-eabi/usr/lib/libc.a
$prefix/bin/clang

Then when compiling things with that clang, you do:

 > $prefix/bin/clang++ -target armv7em-none-eabi 
--sysroot=$prefix/armv7em-none-eabi -T path/to/some/ldscript.ld 
hello_world.cpp -o hw.out



Jon

-- 
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded / Siemens


More information about the llvm-dev mailing list