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.
12 go build
13 exec ./hello
14 stdout Hello
15
16 # Building with -linkmode=external should not say anything about
17 # runtime/cgo (issue #31544).
18 go build -ldflags=-linkmode=external
19 ! stderr runtime/cgo
20 exec ./hello
21 stdout 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.
28 go build -ldflags='-linkmode=external -extldflags=-static'
29 ! stderr runtime/cgo
30 exec ./hello
31 stdout Hello
32
33 -- go.mod --
34 module hello
35
36 go 1.20
37 -- hello.go --
38 package main
39
40 import "fmt"
41
42 func main() {
43 fmt.Println("Hello, world")
44 }
45
View as plain text