That's it, really. I have an x86_64 host that already cross-compiles a C application for android's 4 supported architectures, could I use the existing toolchain to build armeabi-v7a for a Pi (running Linux like Raspbian or whatever)?

Edit 1

I extracted the ext4 filesystem from Raspberry OS and monted it onto /opt/rpi/sysroot.img.

I then tried

~/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/clang \
-target arm-v7a-none-linux-eabi \
-mfloat-abi=hard \
-nostdinc \
-std=c99 \
-isysroot /opt/rpi/sysroot.img \
-c helloRaspi.c

but hit a sort of lib hell. The compiler complains it can't find stdio.h, then stddef.h, etc.

I was under the assumption -isysroot would change the root for the compiler search paths, but i noticed that's not quite what it does, as providing e.g. -I/opt/rpi/sysroot.img/usr/include/c++/8/tr1 will find stdarg.h but -I/usr/include/c++/8/tr1 won't. And what's the difference to --sysroot?

My current compilation line is at

-target arm-v7a-none-linux-eabi 
-isysroot /opt/rpi/sysroot.img 
-I/opt/rpi/sysroot.img/usr/include                          stdio.h
-I/opt/rpi/sysroot.img/usr/include/linux                    stddef.h
-I/opt/rpi/sysroot.img/usr/include/arm-linux-gnueabihf      bits/libc-header-start.h
-I/opt/rpi/sysroot.img/usr/include/c++/8                    tr1/cstdarg
-I/opt/rpi/sysroot.img/usr/include/c++/8/tr1                stdarg.h
-I/opt/rpi/sysroot.img/usr/include/arm-linux-gnueabihf/c++/8  bits/c++config.h
-c helloRaspi.c

(the file names were added of course), but now am getting errors in the included files themselves, such as

In file included from /opt/rpi/sysroot.img/usr/include/stdio.h:43:
/opt/rpi/sysroot.img/usr/include/arm-linux-gnueabihf/bits/types/struct_FILE.h:95:3: error: unknown type name 'size_t'
  size_t __pad5;

which makes me think i got the include path all wrong from the start.

For completeness this is my helloWorld:

#include <stdio.h>

int main(int argc, char* argv[]) {
    printf("hello world\n");
    return 0;

1 Answer 1


I couldn't grok -isysroot and --sysroot, maybe clang handles them differently than gcc (it's not exactly verbose regarding those two options), but I got it to compile as such:

export CLANG=/home/user/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
export SROOT=/opt/rpi/sysroot.img
${CLANG} -v -target arm-hardfloat-linux-gnueabi -mfloat-abi=hard -std=c99 \
-nostdinc \
-I${SROOT}/usr/include \
-I${SROOT}/usr/include/arm-linux-gnueabihf \
-I${SROOT}/usr/lib/gcc/arm-linux-gnueabihf/8/include \
helloRaspi.c -o helloRaspi

Ran successfully on a Raspberry Pi 4 B.~

...whether this is feasible for a larger program remains to be seen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.