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

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

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.

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.

Tim.

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

Sorry for the delay, only just saw this message.

Behalf Of Tim Northover

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