All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] Where the cross-compiler gets shared stuff
@ 2019-11-22  8:00 Frederick Gotham
  2019-11-22  9:37 ` Thomas Preston
  0 siblings, 1 reply; 2+ messages in thread
From: Frederick Gotham @ 2019-11-22  8:00 UTC (permalink / raw)
  To: buildroot

Typically, when a cross-compiler is installed properly on a computer, do you 
need to explicitly invoke it with "--sysroot=/opt/targetfs", or is this 
parameter already implied if the cross-compiler is properly installed? 

Right now I'm working on an embedded Linux project, and I'm using Buildroot 
to produce a minimalistic Linux installation with only the programs and 
libraries I need. 

I see that some 3rd party packages invoke the correct cross-compiler but they 
don't give the "--sysroot" parameter. 

For example, if we start off with the following native compilation command:

    gcc main.c -o prog 

Then a correct cross-compilation would be: 

    CC = /opt/project/build/output/host/bin/x86_64-buildroot-linux-gnu-gcc 
    SYSROOT = /opt/project/build/output/host/x86_64-buildroot-linux-
gnu/sysroot 

    $(CC) --sysroot=$(SYSROOT) main.c -o prog 

I see however that some packages are leaving out the sysroot parameter, and 
so they're just doing: 

    $(CC) main.c -o prog 

This predictably fails if the host and the target have different CPU's, for 
example if my office PC is x86_64 and my target is embedded Linux ARM 
aarch64. 

On my current project though, the host and the target have the same CPU, and 
so if you leave out the "--sysroot" parameter then the program ends up 
linking with shared libraries installed on the host. Sometimes this happens 
without any compiler warning or error! 

So how are cross-compilers supposed to work? If they are installed properly, 
do you need to give them the "--sysroot" parameter?

Note that I'm prefering the use of "--sysroot" instead of using the following 
two options: -I$(STAGING_DIR)/usr/include -L$(STAGING_DIR)/usr/lib.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Buildroot] Where the cross-compiler gets shared stuff
  2019-11-22  8:00 [Buildroot] Where the cross-compiler gets shared stuff Frederick Gotham
@ 2019-11-22  9:37 ` Thomas Preston
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Preston @ 2019-11-22  9:37 UTC (permalink / raw)
  To: buildroot

On 22/11/2019 08:00, Frederick Gotham wrote:
> So how are cross-compilers supposed to work? If they are installed properly, 
> do you need to give them the "--sysroot" parameter?

Check out toolchain/toolchain-wrapper.c, which hardcodes a number of toolchain
arguments (including --sysroot). Cross compiler binaries are accessed via
symlinks in $(HOST_DIR)/bin, some of which go through toolchain-wrapper.

$ ls -l output/host/bin/sparc-linux-*
lrwxrwxrwx 1 tpreston tpreston 46 Nov 21 11:18 output/host/bin/sparc-linux-addr2line -> ../opt/ext-toolchain/bin/sparc-linux-addr2line
lrwxrwxrwx 1 tpreston tpreston 39 Nov 21 11:18 output/host/bin/sparc-linux-ar -> ../opt/ext-toolchain/bin/sparc-linux-ar
lrwxrwxrwx 1 tpreston tpreston 39 Nov 21 11:18 output/host/bin/sparc-linux-as -> ../opt/ext-toolchain/bin/sparc-linux-as
lrwxrwxrwx 1 tpreston tpreston 17 Nov 21 11:18 output/host/bin/sparc-linux-c++ -> toolchain-wrapper
lrwxrwxrwx 1 tpreston tpreston 48 Nov 21 11:18 output/host/bin/sparc-linux-c++.br_real -> ../opt/ext-toolchain/bin/sparc-linux-c++.br_real
lrwxrwxrwx 1 tpreston tpreston 17 Nov 21 11:18 output/host/bin/sparc-linux-cc -> toolchain-wrapper

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-22  9:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-22  8:00 [Buildroot] Where the cross-compiler gets shared stuff Frederick Gotham
2019-11-22  9:37 ` Thomas Preston

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.