C Cross compiling for ARM processor

I want to cross-compile applications for ARM processor on AMD host.
Do i have to recompile clang/llvm & (g)lib(c) with options to do so ?
Idem to setup a compilation toolchain ?
What for meson&automake&autoconf ?
 
Do i have to recompile clang/llvm & (g)lib(c) with options to do so ?
Idem to setup a compilation toolchain ?
Not necessary for recompilation of clang. Only 2 steps you need to do so:

Code:
$ # Example for arm64
$ export SYSROOT="/tmp/sysroot/arm64" TARGET="aarch64-unknown-freebsd"
$
$
$ # 1. Download `sysroot`
$ curl -LSs https://download.freebsd.org/ftp/releases/arm64/13.0-RELEASE/base.txz | \
>   tar Jxf - --include './usr/include/*' --include './usr/lib/*' --include './lib/*' -C ${SYSROOT}
$
$
$ # 2. Compile with the correct arguments
$ clang --target=${TARGET} --sysroot=${SYSROOT} -o foo foo.c
$ clang++ --target=${TARGET} --sysroot=${SYSROOT} -stdlib=libc++ -o bar bar.cpp

Please follow this post written by Marco Cilloni for more details.
 
If i understood correctly i use my default compiler but i say to compile to this "target".
And for the linker i have to download the "target stuff".
 
Pardon me for bumping this old thread, but I have a similar question regarding cross-compilation with Go and cgo (the thing to compiles C code for Go). I've installed the sysroot package and am specifying the target in my CGO_CFLAGS but clang fails with some strange errors, e.g.

Code:
gcc_freebsd_sigaction.c:41:23: error: cast to 'void (*)(int, siginfo_t *, void *)' (aka 'void (*)(i
nt, struct __siginfo *, void *)') from smaller integer type 'uintptr_t' (aka 'unsigned int') [-Werr
or,-Wint-to-pointer-cast]
gcc_freebsd_sigaction.c:43:21: error: cast to 'void (*)(int)' from smaller integer type 'uintptr_t'
(aka 'unsigned int') [-Werror,-Wint-to-pointer-cast]
gcc_freebsd_sigaction.c:63:24: error: cast to smaller integer type 'uintptr_t' (aka 'unsigned int')
from 'void (*)(int, struct __siginfo *, void *)' [-Werror,-Wpointer-to-int-cast]
gcc_freebsd_sigaction.c:65:24: error: cast to smaller integer type 'uintptr_t' (aka 'unsigned int')
from 'void (*)(int)' [-Werror,-Wpointer-to-int-cast]
modules/templates/templates_bindata.go:8: running "go": exit status 1
gmake[1]: *** [Makefile:781: generate-go] Error 1

Code:
CGO_CFLAGS="--target=arm-unknown-freebsd --sysroot=/usr/local/freebsd-sysroot/armv7"

Target is an ARM 32-bit (ARMv7) computer. Am I missing some arguments to clang or some package?

Another bunch of errors:

Update:

Another bunch of errors (got these after solving the above problem):

Code:
# runtime/cgo
gcc_libinit.c:44:8: error: large atomic operation may incur significant performance penalty; the ac
cess size (4 bytes) exceeds the max lock-free size (0  bytes) [-Werror,-Watomic-alignment]
gcc_libinit.c:47:6: error: large atomic operation may incur significant performance penalty; the ac
cess size (4 bytes) exceeds the max lock-free size (0  bytes) [-Werror,-Watomic-alignment]
gcc_libinit.c:49:10: error: large atomic operation may incur significant performance penalty; the a
ccess size (4 bytes) exceeds the max lock-free size (0  bytes) [-Werror,-Watomic-alignment]
gcc_libinit.c:69:9: error: large atomic operation may incur significant performance penalty; the ac
cess size (4 bytes) exceeds the max lock-free size (0  bytes) [-Werror,-Watomic-alignment]
gcc_libinit.c:71:3: error: large atomic operation may incur significant performance penalty; the ac
cess size (4 bytes) exceeds the max lock-free size (0  bytes) [-Werror,-Watomic-alignment]
gmake[1]: *** [Makefile:788: gitea] Error 1
 
target should be armv7-unknown-freebsd13.2-gnueabihf
Thanks, --target=armv7-unknown-freebsd13.2-gnueabihf works but only if I also add --sysroot=/usr/local/freebsd-sysroot/armv7 to CGO_CFLAGS and CGO_LDFLAGS, otherwise ld freaks out about incompatible object format. So my final build command looks like this:

Code:
CC=clang LD=clang GOARCH=arm GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="--target=armv7-unknown-freebsd13.2-g
nueabihf --sysroot=/usr/local/freebsd-sysroot/armv7" CGO_LDFLAGS="--sysroot=/usr/local/freebsd-sysr
oot/armv7
 
Back
Top