You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/10043479/Library/Caches/go-build"
GOENV="/Users/10043479/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/10043479/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/10043479/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6r/y_jqv72j6mlctgk7_k_lkt_0v3s_6z/T/go-build4156745098=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.20.1 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.20.1
uname -v: Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000
ProductName: macOS
ProductVersion: 12.5.1
BuildVersion: 21G83
lldb --version: lldb-1400.0.38.17
Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
What did you do?
package main
import"fmt"funcmain() {
fmt.Println(1)
}
I wrote a simple Go program and ran "go run" and "go build", both of which succeeded and produced the expected result. However, I encountered a problem when running "go tool compile -S ./main.go".
What did you expect to see?
I expected the "go tool compile -S ./main.go" command to output the result normally.
What did you see instead?
go tool compile -S ./main.go
./main.go:3:8: could not import fmt (file not found)
The text was updated successfully, but these errors were encountered:
chimission
changed the title
go tool compile could not import fmt
cmd/compile: go tool compile could not import fmt
Feb 22, 2023
the expectation is that when users want to build Go code they will use "go build" as opposed to running "go tool compile" directly. The command line flags and APIs for "go tool compile" are complicated and tend to change from release to release. Better to let the "go" command invoke the compiler .
In the specific case of getting "-S" output, you can use
$ go build -gcflags=-S main.go
for that. If you want to see the specifics of how the go command is invoking the compiler, try running your build with "-x -work", then look at the transcript:
$ go build -x -work main.go 1> transcript.txt 2>&1
$
If you look at the transcript, you'll see that the Go command is passing in a config file that tells the compiler where to read the export data for the "fmt" package (among others).
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I wrote a simple Go program and ran "go run" and "go build", both of which succeeded and produced the expected result. However, I encountered a problem when running "go tool compile -S ./main.go".
What did you expect to see?
I expected the "go tool compile -S ./main.go" command to output the result normally.
What did you see instead?
The text was updated successfully, but these errors were encountered: