Clang Cross Compiler Options

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
hubris
Member
Member
Posts: 28
Joined: Sun May 24, 2015 12:38 am
Location: Brisbane, Australia

Clang Cross Compiler Options

Post by hubris »

I am struggling to get any coherent cross compiler environment setup, cygwin, windows, and its' just not Linux seem to get in the way. I have tried the wiki pages to create a cross compiled binutils which failed halfway through the make, but I ran the make install anyway as some of the components built (who knows if they will run correctly). Stacking more issues on top of this shakey foundation I went on the try build GCC - which not unexpectedly failed as well.

So I though perhaps I can use the i686-elf binutils that were build and clang++ which is supposed to be able to create a what I want. I might be both thick and confused but it seems that with the right command line options clang++ will compile for another platform - which makes me think that the cross compiling of clang++ itself is to host it on another machine rather than running on a host to generate for a specified target.

So I am using this command line

Code: Select all

CPP32FLAGS	:=	-std=c++1y -Os -target i686-none-elf -ffreestanding -nostdlib -nostdinc -fno-builtin -fno-rtti -fno-exceptions -r -Wall
CPP32		:=	clang++
I have also tried i686-elf the issue is that the output file is in COFF format. A hexdump of the output certainly confirms it is not ELF. So should I go quietly into the forest and shoot myself, or can someone shed some light on either my misunderstanding or how I am using clang.

Thanks in advance
DeltaDrizz
Posts: 4
Joined: Sat Jun 13, 2015 3:28 pm

Re: Clang Cross Compiler Options

Post by DeltaDrizz »

Search via YouTube "how to Build a Cross Compiler". I found the video and it worked great after some tries. To build it without errors and to get it work first time, install "intl" and "diffutils" in addition via Cygwin. Good luck ;)
hubris
Member
Member
Posts: 28
Joined: Sun May 24, 2015 12:38 am
Location: Brisbane, Australia

Re: Clang Cross Compiler Options

Post by hubris »

Ok watched the video, although not quite on target it some extra info, unfortunately so do all of the other sources. Nothing seems to work as stated leading me to wonder if my machine is not cleanly setup.
So I create a new directory, and followed this http://wiki.osdev.org/LLVM_Cross-Compiler tutorial step by step and of course it fails towards the end while linking with an error saying something like _registerframe is not found, sorry for the vagueness I am in the middle of another 4 hour build.
I also tried to find if clang could build clang, once again a lot of positive hints but nothing definitive. I even tried setting the CC and CXX variables prior to the configure and once again clang uses gcc and g++ to build. So it seems that there is more information required.
Lastly I still cannot tell if clang is a front end to gnu tools or a replacement for them. mighty grumble...

Anyway has anyone actually built clang successfully on windows using either clang or gnu?
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: Clang Cross Compiler Options

Post by Octocontrabass »

hubris wrote:I have tried the wiki pages to create a cross compiled binutils which failed halfway through the make,
This suggests problems with your build environment. That's probably why things aren't working.

I haven't built clang before (it doesn't support all of my target CPU architectures), but I have built binutils and gcc, so I might be able to help you get a build environment that can at least do that much.
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Clang Cross Compiler Options

Post by Roman »

Clang is a front-end for the LLVM framework. I use clang for building object files and GNU binutils for linking them. You probably need to use this option: --target=i686-pc-none-elf
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
hubris
Member
Member
Posts: 28
Joined: Sun May 24, 2015 12:38 am
Location: Brisbane, Australia

Re: Clang Cross Compiler Options

Post by hubris »

well I have stripped all cygwin off of my machine, followed the video exactly as stated and of course it does not work as stated. The configure refused to guess at the host triple so after some fudging around I used i386-coff which allowed the configure to execute none of the many combinations of i686-[pc,unknown]-[coff,elf] worked.

So configure ran and then make failed with an error

Code: Select all

../../binutils-2.9.1/gas/config/tc-i386.h:396:32: error: array type has incomplete element type
 extern const struct relax_type md_relax_table[];
                                ^
Makefile:1291: recipe for target 'app.o' failed
So now I wonder why i386 and not i686 and all of the other issues still leading me to my environment. So I think the next step is to rebuild my machine and hope which ever gremlin is resident is cast out after the re-build.
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: Clang Cross Compiler Options

Post by Octocontrabass »

hubris wrote:binutils-2.9.1
I'm not surprised a 17-year-old version of binutils can't figure out the host triple.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: Clang Cross Compiler Options

Post by kzinti »

What's more, the tutorial says to get a recent version (2.21 or above).
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Clang Cross Compiler Options

Post by thepowersgang »

In software terms, 2.21 is newer than 2.9 (they're not decimals, it's just a period used to separate different numbers)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply