Go程序未使用1.4.2静态链接

标签 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 一起使用。构建成功,但程序未静态链接。

有谁知道这是怎么回事吗?

最佳答案

出现更多搜索 this thread in the golang issue tracker由于 1.3 和 1.4 之间的更改,无法静态链接导入 net 包的程序。

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

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

这对我有用。构建成功并生成静态链接程序。

关于Go程序未使用1.4.2静态链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30954159/

相关文章:

c++ - MSVC项目中使用的Mingw静态库

c++ - 虚幻引擎 4 链接静态第 3 方库/SDK (libZPlay)

go - go语言解析嵌套JSON

运行 Go 应用程序的多个实例时的 Gorilla websocket 连接

gcc - 将 OpenMP 与 GCC 静态链接

class - 从 D 中的静态库加载类

c++ - 对 boost 库的 undefined reference

amazon-web-services - AWS-SDK : SQS How identify messages that were not deleted in BatchDeleteOperation

arrays - 如何解码 json 并填充到 golang 中的结构

testing - 登录golang测试可以吗?还是不进行登录测试是一种做法?