how to compile in one system targeting another?

Xi Ruoyao ryxi@stu.xidian.edu.cn
Sat Oct 21 12:53:00 GMT 2017


On 2017-10-21 12:41 +0100, Toebs Douglass wrote:
> On 21/10/17 04:07, sugar wrote:
> > Hi, how could for instance, compile a source in my server, but the actual
> > target will be another server, should I enable certain special flags at the
> > time of the compilation?
> 
> I may be wrong, but as I understand it, GCC has the notion of a host, a 
> target and a build.
> 
> The host is the platform (OS, processor, etc) which runs GCC.
> 
> The target is the platform GCC emits code for.
> 
> The build is the platform which is actually building this GCC.

For example, if you have a ARM laptop, and a x86_64 workstation, and you
want to develop programs for AVR MCUs on your ARM laptop, you could invoke

    gccsrcdir/configure --host=x86_64-linux-gnu \
      --target=arm-linux-gnueabihf --build=x86_64-linux-gnu

on your workstation.  You'll build arm-linux-gnueabihf-gcc running on
x86_64-linux-gnu.  Then invoke

    gccsrcdir/configure --host=arm-linux-gnueabihf --target=avr \
      --build=x86_64-linux-gnu

on your workstation.  Then you can build avr-gcc running on
arm-linux-gnueabihf.

To use --host=X-Y-Z, you must have X-Y-Z-gcc.  And to build X-Y-Z-gcc
you need X-Y-Z-binutils.  To build "useful" programs such as a simple
hello world program, you need to build libc for X-Y-Z with X-Y-Z-gcc.

> Building GCC IME, although I'm barely competent in Linux, was for me an 
> extraordinarily difficult, painful, error and mistake prone and time 
> consuming process.  I would even call it agonizing.  I'm afraid that 
> given the questions you're asking, you may not realise how staggeringly 
> difficult the task you are attempting is.

Yes.  To bootstrap X-Y-Z-binutils, X-Y-Z-gcc and libc for X-Y-Z, you
have to use some strange configuration flags.  Cross LFS
<http://clfs.org> would be an useful reference if you want to do that.
-- 
Xi Ruoyao <ryxi@stu.xidian.edu.cn>
School of Aerospace Science and Technology, Xidian University
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2553 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20171021/e66d72f7/attachment.bin>


More information about the Gcc-help mailing list