[LLVMdev] Is cross-compiling for ARM on x86 with llvm/Clang possible?

1,046 views
Skip to first unread message

Negar Mir

unread,
Nov 21, 2012, 12:26:58 PM11/21/12
to llv...@cs.uiuc.edu
Hi Journeyer J. Joh,

Thank you so much for the solution. It was very helpful. Now, I'm wondering if you have tested compiling a whole project (with several .c/.cpp files) and achieve one binary file. Previously (on X86), I built .bc files separately and then I used llvm-link to get one .bc file and produce one binary file for the whole project. But, this time I encountered some errors like the following, and it seems that it cannot link to the appropriate ARM libraries.

In file included from ../../../../LLVM/project/file1.cpp:8:
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../include/c++/4.6/iostream:38:10: fatal error:
      'bits/c++config.h' file not found
#include <bits/c++config.h>
         ^

Thanks
Negar

Tim Northover

unread,
Nov 21, 2012, 1:13:50 PM11/21/12
to Negar Mir, LLVM Developers Mailing List
Hi Negar,

> In file included from ../../../../LLVM/project/file1.cpp:8:
> /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../include/c++/4.6/iostream:38:10:
> fatal error:
> 'bits/c++config.h' file not found
> #include <bits/c++config.h>
> ^

That's a compile-time error rather than link-time. Clang does its best
to find all the bits of the cross-toolchain it needs, but it doesn't
always succeed. The immediate error is it not knowing about the
directory where c++config.h is stored, but in fact that path it's
getting "iostream" from looks a little dodgy too. If I'm calculating
my ..s correctly, it's "/usr/include/c++/4.6/iostream" which is
probably the host's copy. It *may* be compatible, but then again it
may not.

Some combination of --sysroot, -gcc-toolchain and -target may be
enough, but for more complex installations you may need to manually
give it some -isystem options too.

What clang command-line (and/or configure options) are you using to
tell it where to find the arm-linux-gnueabi toolchain?

Tim.
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Tim Northover

unread,
Nov 21, 2012, 1:15:42 PM11/21/12
to Negar Mir, LLVM Developers Mailing List
> What clang command-line (and/or configure options) are you using to
> tell it where to find the arm-linux-gnueabi toolchain?

Never mind, it looks like there's another thread with that information.

Journeyer J. Joh

unread,
Nov 21, 2012, 7:26:37 PM11/21/12
to Negar Mir, llv...@cs.uiuc.edu
Hello Negar Mir,

It's good that my experience help someone.

For me, this kind of errors require to put '-v' option in the build
command line so that the the exact build command can be exposed.

I compiled with the options below.
-ccc-host-triple $(CCC_HOST_TRIPLE_ARM) \
--sysroot=$(SYSROOT_ARM) \
-gcc-toolchain $(GCC_TOOLCHAIN)

And this options below needed to run compiled binary on the target.
-Wl,-dynamic-linker,/lib/ld-linux.so.3 (the version must be matched to
the one in the target)

But I haven't tried like you - mix .bc file with .c, .cpp to build a
final output.

I recommend you check with '-v' option.

Good luck!
Journeyer


2012/11/22 Negar Mir <nmir...@gmail.com>:
> _______________________________________________
> LLVM Developers mailing list
> LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>



--
----------------------------------------
Journeyer J. Joh
o o s a p r o g r a m m e r
a t
g m a i l d o t c o m
----------------------------------------

David Tweed

unread,
Nov 22, 2012, 4:08:37 AM11/22/12
to Tim Northover, Negar Mir, LLVM Developers Mailing List
Sorry for the delay, only just saw this message.

-----Original Message-----
From: llvmdev...@cs.uiuc.edu [mailto:llvmdev...@cs.uiuc.edu] On
Behalf Of Tim Northover
Sent: 21 November 2012 18:14
To: Negar Mir
Cc: LLVM Developers Mailing List
Subject: Re: [LLVMdev] Is cross-compiling for ARM on x86 with llvm/Clang
possible?

Hi Negar,

> In file included from ../../../../LLVM/project/file1.cpp:8:
>
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../include/c++/4.6/iostream:38:1
0:
> fatal error:
> 'bits/c++config.h' file not found
> #include <bits/c++config.h>
> ^

| That's a compile-time error rather than link-time. Clang does its best
| to find all the bits of the cross-toolchain it needs, but it doesn't
| always succeed. The immediate error is it not knowing about the
| directory where c++config.h is stored, but in fact that path it's
| getting "iostream" from looks a little dodgy too. If I'm calculating
| my ..s correctly, it's "/usr/include/c++/4.6/iostream" which is
| probably the host's copy. It *may* be compatible, but then again it
| may not.

From work on the pandaboard transition to hard float, I discovered the way
that this works is clang tries to find the gcc installation for the platform
you're compiling for, then locates headers relative to that with ..'s . The
idea is that natively it'll end up at "/usr/..." while you'd typically
install cross-compilers in a different place and this will end up at the
cross-compile targets. So the first thing to do is figure out which
bits/c++config.h file corresponds to the ARM cross compile environment, and
where it resides relative to the /usr/lib/gcc/arm-linux-gnueabi/4.6
directory. If it's not in the expected place then you may need, as Tim says,
to specify some files manually or go for a different cross-compiler
installation.

(Note: I explicitly disavow understanding this stuff, it's purely at the
level of "if you do this things work".)

Gordon Keiser

unread,
Nov 23, 2012, 12:03:03 AM11/23/12
to Negar Mir, llv...@cs.uiuc.edu

If /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../include/c++/4.6/ is the proper c++ include directory for your toolchain, I'm guessing bits/c++config.h will be located at

/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../include/c++/4.6/arm-linux-gnueabi/bits/c++config.h …  many of the arm cross toolchains (codesourcery for example) seem to be structured this way, although clang doesn't (or didn't as of 3.1) detect this layout.  Adding an include for that /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../include/c++/4.6/arm-linux-gnueabi/bits should fix it. 

 

Cheers,

Gordon Keiser
Software Development Engineer

Arxan Technologies

Reply all
Reply to author
Forward
0 new messages