...
1[short] skip 'links and runs binaries'
2
3# This test requires external linking. Assume that if cgo is supported
4# then external linking works.
5[!cgo] skip 'requires a C linker'
6
7# Only run on Unix systems.
8[GOOS:windows] skip
9[GOOS:plan9] skip
10
11# Ordinary build should work.
12go build
13exec ./hello
14stdout Hello
15
16# Building with -linkmode=external should not say anything about
17# runtime/cgo (issue #31544).
18go build -ldflags=-linkmode=external
19! stderr runtime/cgo
20exec ./hello
21stdout Hello
22
23# Some targets don't support -static
24[GOOS:darwin] skip 'no static linking on Darwin'
25[GOOS:solaris] skip 'no static linking on Solaris'
26
27# Building with -linkmode=external -extldflags=-static should work.
28go build -ldflags='-linkmode=external -extldflags=-static'
29! stderr runtime/cgo
30exec ./hello
31stdout Hello
32
33-- go.mod --
34module hello
35
36go 1.20
37-- hello.go --
38package main
39
40import "fmt"
41
42func main() {
43 fmt.Println("Hello, world")
44}
View as plain text