On Thu, Jun 1, 2023 at 4:30 PM ron flory via users
<users@lists.fedoraproject.org> wrote:
>
> Hi- am hopefully missing something dumb/obvious here---
>
>  Am trying to cross-compile for raspberry-pi, but some basic headers appear 
> to be missing, or not redirecting to 'generics'.
>
> -----
> Install the cross-compiler(s):
>     dnf install gcc-aarch64-linux-gnu  gcc-c++-aarch64-linux-gnu
>
> -----
> Compile hello_world sample:
>     aarch64-linux-gnu-gcc  hello_world.cpp -o hello_world
>
> Results:
> hello_world.c:1:10: fatal error: stdio.h: No such file or directory
>     1 | #include <stdio.h>
>       |          ^~~~~~~~~
> compilation terminated.
>
> -----
> Hello_world sample consists of:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char *argv[])
> {
>         printf("Hello World\n");
>         return(0);
> }

When cross-compiling, you typically need to setup the tools (for the
cross-compile) and the include and library path (for the
cross-compile). Assuming aarch64-linux-gnu-gcc is the only tool you
need, you are still missing include and library paths.

You can add include and library paths via --isysroot and --sysroot. So
something like:

    AARCH64_INCL="..."
    AARCH64_LIB="..."
    aarch64-linux-gnu-gcc -o hello_world \
        --isysroot="${AARCH64_INCL}" hello_world.cpp \
        --sysroot="${AARCH64_LIB}"

When you are building for the host, like x86_64, stuff is found in
/usr by default, and you don't need to specify --isysroot and
--sysroot.

When building for aarch64, your cross-compile headers will be
somewhere like /usr/aarch64/include, and libraries will be in
/usr/aarch64/lib. So you would use AARCH64_INCL=/usr/aarch64 and
AARCH64_LIB=/usr/aarch64. --isysroot should add the trailing include/
for you, and --sysroot should add the trailing lib/ for you.

In reality, it is usually a little more complex, like when building a
library for Android or iOS. In this case you usually want to set your
tools, too. (Tools like CC, CXX, AR and LD). For an example of scripts
that setup those environments, see
https://github.com/weidai11/cryptopp/blob/master/TestScripts/setenv-android.sh
and https://github.com/weidai11/cryptopp/blob/master/TestScripts/setenv-ios.sh
.

Jeff
_______________________________________________
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Reply via email to