Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: cgo-related compile errors yield poor error messages #29195

Closed
MMulthaupt opened this issue Dec 12, 2018 · 2 comments

Comments

@MMulthaupt
Copy link

commented Dec 12, 2018

What version of Go are you using (go version)?

go version go1.11.2 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/martin/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/martin/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build515058236=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Natively compile a modularized Go project with CGO_ENABLED=1 on Linux.

What did you expect to see?

A descriptive error informing me which import-statement in which .go-file caused the problem.

What did you see instead?

The following mostly C-related error output, which requires me to debug the issue by selectively removing module dependencies and such until the problem is resolved to get closer to identifying the offending import/include:

# runtime/cgo
In file included from _cgo_export.c:3:0:
/usr/include/stdlib.h:25:10: fatal error: bits/libc-header-start.h: No such file or directory
 #include <bits/libc-header-start.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

While runtime/cgo is mentioned, this is certainly not being imported by me directly. Also great would be to report common missing dependencies in case of known failures. (I.e. answer the question "What am I missing which contains the missing file?")

@ALTree ALTree changed the title CGO-related compile errors yield poor error messages cmd/cgo: cgo-related compile errors yield poor error messages Dec 12, 2018

@ALTree ALTree added this to the Unplanned milestone Dec 12, 2018

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Dec 12, 2018

It's a hard problem. The code that failed to compile is in fact in the standard library's runtime/cgo package. That package does a #include <stdlib.h>. It appears that on your system that does not work. So there seems to be something deeply broken in your C compiler installation. Since we didn't write or install the C compiler, it's very hard for us to give you a useful error report, or to answer a question like what you are missing.

The first result on a Google search for the C compiler error message suggested

sudo apt-get install gcc-multilib g++-multilib

so I would try that.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Dec 12, 2018

I don't really see what we can do better here, so I'm going to close this issue. Please comment if you have a suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.