cgo cross compilation to arm failed

299 views
Skip to first unread message

Hubert Hirtz

unread,
Sep 6, 2020, 4:54:05 PM9/6/20
to golan...@googlegroups.com
Hello go-nuts,

I am trying to cross-compile a project that depends on sqlite3 on a
amd64 machine (host) for an armhf machine (target), using clang with the
appropriate "--target" flag.

The build fails on runtime/cgo with the following errors:

```
# runtime/cgo
In file included from gcc_libinit.c:8:
/usr/include/pthread.h:672:6: error: 'regparm' is not valid on this platform
/usr/include/bits/pthreadtypes-arch.h:52:50: note: expanded from macro
'__cleanup_fct_attribute'
In file included from gcc_libinit.c:8:
/usr/include/pthread.h:684:3: error: 'regparm' is not valid on this platform
/usr/include/bits/pthreadtypes-arch.h:52:50: note: expanded from macro
'__cleanup_fct_attribute'
In file included from gcc_libinit.c:8:
/usr/include/pthread.h:725:6: error: 'regparm' is not valid on this platform
/usr/include/bits/pthreadtypes-arch.h:52:50: note: expanded from macro
'__cleanup_fct_attribute'
```

Here is the `go env` and the full build output (run with `-x`):
<https://paste.sr.ht/~taiite/b6b47c78cc399d41b398f1076f55a5a1cc75526e>

Do you have any idea why it fails or if I missed something?

Cheers

signature.asc

Ian Lance Taylor

unread,
Sep 7, 2020, 3:27:39 PM9/7/20
to Hubert Hirtz, golang-nuts
In order to cross-compile a Go program that uses cgo, you need a
complete C cross-compiler. In this case your C cross-compiler appears
to be using the native header files, which can't work. It needs to
use the cross-compiler header files.

Ian

Amnon

unread,
Sep 8, 2020, 5:08:28 AM9/8/20
to golang-nuts
Cross compilation of CGO stuff requires a lot of faff.

I spend several years doing embedded development, and messing about 
with GCC build-chains. So I was absolutely astounded that the Go build tools
do everything with two env vars.

Once you branch out to CGO, you are back in the hairy world of GCC cross
compilation tool chains. I say turn back if you can!

My advice, if you need sqlite, is to switch to https://gitlab.com/cznic/sqlite
which is a pure Go version. I haven't tried it. But if it spared people 
the pain of CGO, then it is worth its weight in gold.

Jan Mercl

unread,
Sep 13, 2020, 10:01:56 AM9/13/20
to Hubert Hirtz, golang-nuts
On Sun, Sep 6, 2020 at 10:53 PM 'Hubert Hirtz' via golang-nuts
<golan...@googlegroups.com> wrote:

> I am trying to cross-compile a project that depends on sqlite3 on a
> amd64 machine (host) for an armhf machine (target), using clang with the
> appropriate "--target" flag.
>
> The build fails on runtime/cgo with the following errors:

It might be possible that the CGo-free SQLite port at
modernc.org/sqlite [0] can be used. Release v1.7.0 now supports arm[1]
and arm64[2].

[0]: https://godoc.org/modernc.org/sqlite
[1]: https://gitlab.com/cznic/sqlite/-/blob/f228816300a40a6f8cd90293a629fffad952c6ce/testdata/testlog-linux-arm
[2]: https://gitlab.com/cznic/sqlite/-/blob/f228816300a40a6f8cd90293a629fffad952c6ce/testdata/testlog-linux-arm64

Hubert Hirtz

unread,
Sep 14, 2020, 8:16:50 AM9/14/20
to Jan Mercl, golang-nuts
Thank you, that was the issue. I used one of the toolchains from
<http://musl.cc> and it worked.

signature.asc
Reply all
Reply to author
Forward
0 new messages