使用1.4.2将程序静态链接起来

时间:2015-06-20 12:43:48

标签: go static-linking

尝试构建运行http服务器的go程序的静态链接版本,并使用net包来确定和解析传入请求的IP地址。使用此构建语句:

CGO_ENABLED=0 go install -a -ldflags '-s' .

这个序言在我的节目中:

package main

import (
    "encoding/json"
    "errors"
    "fmt"
    "log"
    "net"
    "net/http"
    "path/filepath"
    "strings"

    "golang.org/x/blog/content/context/userip"

    "github.com/oschwald/maxminddb-golang"
)

这个工作建立了go 1.3,产生了一个静态链接的程序,但是没有使用go 1.4.2。构建成功,但程序没有静态链接。

有谁知道发生了什么事?

1 个答案:

答案 0 :(得分:5)

由于1.3和1.4之间的变化导致无法静态链接导入net软件包的程序,因此更多搜索this thread in the golang issue tracker

向下阅读我发现this workaround suggested by ianlancetaylor使用-installsuffix开关指定cgo。这使我的构建声明:

CGO_ENABLED=0 go install -a -installsuffix cgo -ldflags '-s' .

哪个适合我。构建成功并生成静态链接程序。

相关问题