That works better although not perfectly for my purposes. More work 
required from me.

I'm curious though, about the -marm flag. How can I remove it from the 
GOGCCFLAGS variable? Or are we saying we can't use the aarch64 compiler in 
conjunction with cgo?

Thanks for the help

On Wednesday, 15 November 2023 at 20:05:59 UTC Jan Mercl wrote:

> On Wed, Nov 15, 2023 at 8:30 PM Stephen Illingworth <
> [email protected]> wrote:
> > I'm trying to build a project on the Raspberry Pi, natively.
> >
> > Using "go env" I can see that Go has the following value for GOGCCFLAGS
> >
> > GOGCCFLAGS='-fPIC -marm -Wl,--no-gc-sections -fmessage-length=0 
> -ffile-prefix-map=/tmp/go-build745518569=/tmp/go-build 
> -gno-record-gcc-switches'
> >
> > However, the native compiler (gcc 12.2) does not have the -marm flag. 
> The compilation of the project fails.
>
> From the above I guess you might be running gcc for aarch64 as the arm 
> version accepts the -marm flag here:
>
> jnml@pi32:~/tmp/gcc$ go version
> go version go1.21.4 linux/arm
> jnml@pi32:~/tmp/gcc$ cat main.c 
> #include <stdio.h>
>
> int main() {
> printf("Hello, world!\n");
> }
> jnml@pi32:~/tmp/gcc$ rm -f a.out ; gcc -marm main.c && ./a.out && echo ok
> Hello, world!
> ok
> jnml@pi32:~/tmp/gcc$ gcc --version
> gcc (Raspbian 10.2.1-6+rpi1) 10.2.1 20210110
> Copyright (C) 2020 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> jnml@pi32:~/tmp/gcc$ 
>
> I tried the solution from 
> https://jensd.be/1126/linux/cross-compiling-for-arm-or-aarch64-on-debian-or-ubuntu
>  
> and it seems to work fine:
>
> jnml@pi64:~/tmp/gcc$ jnml@pi64:~/tmp/gcc$ go version
> go version go1.21.4 linux/arm64
> jnml@pi64:~/tmp/gcc$ cat main.c
> #include <stdio.h>
>
> int main() {
> printf("Hello, world!\n");
> }
> jnml@pi64:~/tmp/gcc$ rm -f a.out ; gcc main.c && ./a.out && echo ok
> Hello, world!
> ok
> jnml@pi64:~/tmp/gcc$ rm -f a.out ; gcc -marm main.c && ./a.out && echo ok
> gcc: error: unrecognized command-line option ‘-marm’
> jnml@pi64:~/tmp/gcc$ sudo apt install gcc-arm-linux-gnueabi 
> binutils-arm-linux-gnueabi
> ...
> jnml@pi64:~/tmp/gcc$ rm -f a.out ; arm-linux-gnueabi-gcc -marm main.c && 
> file a.out
> a.out: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically 
> linked, interpreter /lib/ld-linux.so.3, 
> BuildID[sha1]=2191a16290d46b039bfae26fd5918106dff99749, for GNU/Linux 
> 3.2.0, not stripped
> jnml@pi64:~/tmp/gcc$
>
> HTH
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/af718786-7479-4a98-bfb2-7feee41017can%40googlegroups.com.

Reply via email to