xgo: Unable to build for target linux/amd64.

Today I was setting up a new building environment, and was unable to build for target linux/amd64.

At first I xgo gave me the following error message, and I thought that it was ldflags which broke the build:

Compiling for linux/amd64...
panic: path "--ldflags= -extldflags \"-static\"" not in error "invalid import path \"--ldflags= -extldflags \\\"-static\\\"\"" [recovered]
	panic: path "--ldflags= -extldflags \"-static\"" not in error "invalid import path \"--ldflags= -extldflags \\\"-static\\\"\""

goroutine 1 [running]:
cmd/go/internal/load.(*preload).flush(0xc000282050)
	/usr/local/go/src/cmd/go/internal/load/pkg.go:1086 +0x78
panic({0x97d420, 0xc0003f5430})
	/usr/local/go/src/runtime/panic.go:884 +0x212
cmd/go/internal/load.ImportErrorf({0x7ffe042a3c52, 0x20}, {0xa2f3a2?, 0x20?}, {0xc000135630?, 0xc000135b18?, 0x0?})
	/usr/local/go/src/cmd/go/internal/load/pkg.go:523 +0x199
cmd/go/internal/load.(*Package).load(0xc00068f700, {0xb2e690, 0xc000026160}, {0x0, 0x0, 0x0, 0x1, 0x0, 0x0}, {0x7ffe042a3c52, ...}, ...)
	/usr/local/go/src/cmd/go/internal/load/pkg.go:1894 +0x147d
cmd/go/internal/load.loadImport({0xb2e690, 0xc000026160}, {0x0, 0x0, 0x0, 0x1, 0x0, 0x0}, 0xc000282050, {0x7ffe042a3c52, ...}, ...)
	/usr/local/go/src/cmd/go/internal/load/pkg.go:744 +0x570
cmd/go/internal/load.PackagesAndErrors({0xb2e690?, 0xc000026160?}, {0x0, 0x0, 0x0, 0x1, 0x0, 0x0}, {0xc0000240d0, 0x9, ...})
	/usr/local/go/src/cmd/go/internal/load/pkg.go:2794 +0x87b
cmd/go/internal/work.runBuild({0xb2e690, 0xc000026160}, 0xc00002e4b0?, {0xc0000240d0, 0x9, 0x9})
	/usr/local/go/src/cmd/go/internal/work/build.go:408 +0xba
main.invoke(0xe298a0, {0xc0000240c0, 0xa, 0xa})
	/usr/local/go/src/cmd/go/main.go:225 +0x34e
main.main()
	/usr/local/go/src/cmd/go/main.go:179 +0x7d1

Then I proceeded to try building without ldflags flag, and xgo still failed:

Compiling for linux/amd64...
malformed import path "--tags": leading dash
package netgo is not in GOROOT (/usr/local/go/src/netgo)
malformed import path "--ldflags= ": leading dash
malformed import path "--gcflags=": leading dash
malformed import path "-o": leading dash

Here is my command for building the package:

xgo -tags 'netgo' -ldflags  '-extldflags "-static"' --targets=linux/amd64 .

It seems that pull request #180 broke some string concatenation stuff in docker/base/build.sh. And with an older xgo Docker image, the building process succeeded:

xgo -image techknowlogick/xgo:go-1.19.2 -tags 'netgo' -ldflags  '-extldflags "-static"' --targets=linux/amd64 .

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I just saw your comment above using the printf which I think is the way to go so I’ve pushed that up to the PR

Damn! Sorry about this!

I have another PR that should fix that.