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/go: rebuilds standard library inappropriately in modules mode #28333

Closed
sviechnikov opened this issue Oct 23, 2018 · 22 comments

Comments

Projects
None yet
4 participants
@sviechnikov
Copy link

commented Oct 23, 2018

Please answer these questions before submitting your issue. Thanks!

What did you do?

package main

import (
	"log"
	"net/http"
)

func main() {
	log.Fatal(http.ListenAndServe(":8080", nil))
}

What did you expect to see?

Listening of http server

What did you see instead?

 net
/usr/local/go/src/net/cgo_bsd.go:11:10: fatal error: 'netdb.h' file not found
#include <netdb.h>
         ^~~~~~~~~
1 error generated.

System details

go version go1.11.1 darwin/amd64
GOARCH="amd64"
GOBIN="/Users/max/Projects/go/bin"
GOCACHE="/Users/max/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/max/Projects/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/max/Projects/edu/go/polygraph/go.mod"
GOROOT/bin/go version: go version go1.11.1 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.11.1
uname -v: Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.14
BuildVersion:	18A391
lldb --version: lldb-1000.11.37.1
  Swift-4.2
@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 23, 2018

After Google search, I've decided to create this ticket, because INET don't know about this issue ....
From beginning, I've used 1.11 version, but after facing with this bug - made upgrade to the 1.11.1, but still have the same trouble.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Oct 23, 2018

What command did you run to get that error?

@bcmills bcmills changed the title Error when trying to start http server or make an request using `net/http` net/http: Error when trying to start http server or make an request using `net/http` Oct 23, 2018

@bcmills bcmills changed the title net/http: Error when trying to start http server or make an request using `net/http` net/http: Error when trying to start http server or make a request Oct 23, 2018

@bcmills bcmills added this to the Go1.12 milestone Oct 23, 2018

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

@ianlancetaylor just go build ./path/to/the/file.go. Listing of the file on top of the conversation

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

Go was installed using official bundle and tried with brew.... Nothing helps

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

I recently used MacOS 10.13 and everything worked fine .... Maybe after update to 10.14 some required by Go system dependencies was lost (I mean, Apple developers deprecated or changed some things and we got this issues)

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

Little bit about C

$(go env CC) --version:

clang version 5.0.1 (tags/RELEASE_501/final)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

===

which $(go env CC):

/usr/local/opt/llvm/bin/clang
@agnivade

This comment has been minimized.

Copy link
Member

commented Oct 24, 2018

Can you do a GOCACHE=off go build -x -v path/to/file.go ?

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

@agnivade I've got

WORK=/var/folders/q4/gxzbpbqx7bgcllkbph02xcmm0000gn/T/go-build066535883
go: cannot use modules with build cache disabled
@agnivade

This comment has been minimized.

Copy link
Member

commented Oct 24, 2018

Since you are just compiling a single file, you don't need modules. Can you try without module mode ?

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

@agnivade I have a multi bundled project, few entry points .... My code described above - just an example

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

@agnivade Ok, I will in another project to run without modules

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

@agnivade Yeah, without module mode - it is working. Compiled successfully

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

@agnivade So, I've moved my project to the $GOPATH and it was compiled successfully. Looks like this is issue in module mode.

@sviechnikov sviechnikov changed the title net/http: Error when trying to start http server or make a request net/http: Error when trying to start http server or make a request (module mode) Oct 24, 2018

@agnivade

This comment has been minimized.

Copy link
Member

commented Oct 24, 2018

I am still unable to reproduce this.

In an empty dir, I copied your file. Then

go mod init .
GO111MODULE=on go build -x -v file.go

This prints a long log, but builds successfully. I am on linux though.

Can you try doing a go clean -i -r -modcache and then compiling again ?

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

@agnivade Unfortunately the same error. I think it is can be reproduced with latest MacOS. By the way, it's worked before upgrade of OS.... Maybe something was changed into the OS core things... Because, i've defiged go.mod through go mod init, it was created file with module github.com/sviechnikov/project_name and all was fine

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

@agnivade How do you think, it is can be an issue?
I've reinstalled xcode tools again (how told stackoverflow and my colleagues), but it's won't help

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

One more thing, I've searched for this file netdb.h and found it in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/, but looks like go dependencies not looking there

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

how I understand, Clang expecting /usr/include to be this libraries folder .... Maybe I'm something missing, because Clang is not my strong point

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

@agnivade In module mode works with CGO_ENABLED=0 go build cmd/server/main.go

@sviechnikov

This comment has been minimized.

Copy link
Author

commented Oct 24, 2018

But I hope, this is temporary ...

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Oct 24, 2018

Likely the same as #26988: in some cases the go tool is incorrectly deciding that it needs to rebuild the standard library.

@ianlancetaylor ianlancetaylor changed the title net/http: Error when trying to start http server or make a request (module mode) cmd/go: rebuilds standard library inappropriately in modules mode Oct 24, 2018

@bcmills

This comment has been minimized.

Copy link
Member

commented Oct 24, 2018

Closing as duplicate of #26988.

@bcmills bcmills closed this Oct 24, 2018

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