Build error from pragma warnings when doing "go build -buildmode=c shared..."

295 views
Skip to first unread message

Aaron Epstein

unread,
May 20, 2021, 7:47:09 AM5/20/21
to golang-nuts
Hi,

I am seeing a compiler error when building a shared c library from a go program. The error is:

GO111MODULE=on go build -buildmode=c-shared -o mylib.so myfile.go
# runtime/cgo
cc1: warnings being treated as errors
_cgo_export.c:6: warning: ignoring #pragma GCC diagnostic
_cgo_export.c:7: warning: ignoring #pragma GCC diagnostic
_cgo_export.c:8: warning: ignoring #pragma GCC diagnostic

CGO_ENABLED=1 is set as well. This is using go 1.13. Any ideas?

Thanks,
Aaron

Ian Lance Taylor

unread,
May 20, 2021, 9:36:57 AM5/20/21
to Aaron Epstein, golang-nuts
What C compiler are you using?  What version?

Ian

Aaron Epstein

unread,
May 20, 2021, 9:46:34 AM5/20/21
to golang-nuts
gcc

Is there a way to see which version go is picking up? I have both 4.9.4 and 4.1.2. I suspect it is picking up 4.1.2 and this is the cause, but is there a way to tell?

Aaron Epstein

unread,
May 20, 2021, 10:05:22 AM5/20/21
to golang-nuts
Removing gcc 4.1.2 from PATH so it picked up 4.9.4 which resolved this issue.

Still would be good to know if it is possible to know which gcc go is using...

Manlio Perillo

unread,
May 20, 2021, 10:23:43 AM5/20/21
to golang-nuts
Note that you can explicitly tell go the C compiler to use, by setting the CC environment variable.
As an example:
go env -w CC=path-to-gcc4.9.4


Manlio

Shulhan

unread,
May 20, 2021, 10:54:21 AM5/20/21
to Aaron Epstein, golang-nuts
On Thu, 20 May 2021 07:05:22 -0700 (PDT)
Aaron Epstein <slugge...@gmail.com> wrote:

> Removing gcc 4.1.2 from PATH so it picked up 4.9.4 which resolved
> this issue.
>
> Still would be good to know if it is possible to know which gcc go is
> using...
>

As addition to Manlio reply, for more information about using cgo

https://golang.org/cmd/cgo/

Snip from,

"... The default C and C++ compilers may be changed by the CC and CXX
environment variables, respectively; those environment variables may
include command line options."

Ian Lance Taylor

unread,
May 20, 2021, 1:22:28 PM5/20/21
to Aaron Epstein, golang-nuts
On Thu, May 20, 2021 at 6:46 AM Aaron Epstein <slugge...@gmail.com> wrote:
>
> gcc
>
> Is there a way to see which version go is picking up? I have both 4.9.4 and 4.1.2. I suspect it is picking up 4.1.2 and this is the cause, but is there a way to tell?

With bash on Unix systems, run

$(go env CC) --version

GCC 4.1.2 came out in 2007. I guess we no longer support it. I think
that's OK.

GCC 4.9.4 came out in 2016.

The most recent GCC release is 11.1.

Ian
Reply all
Reply to author
Forward
0 new messages