dongwu5743 2015-06-20 12:43
浏览 43
已采纳

Go程序未使用1.4.2静态链接

Trying to build a statically linked version of a go program that runs an http server, and uses the net package to determine and parse the IP address of the incoming request. With this build statement:

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

And this preamble in my program:

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"
)

This worked building with go 1.3, producing a statically linked program, but is not working with go 1.4.2. The build succeeds, but the program is not statically linked.

Does anyone know what is going on?

  • 写回答

1条回答 默认 最新

  • dongyong2063 2015-06-20 12:43
    关注

    More searching turned up this thread in the golang issue tracker about being unable to statically link a program that imports the net package due to changes between 1.3 and 1.4.

    Reading down I found this workaround suggested by ianlancetaylor to use the -installsuffix switch to specify cgo. This made my build statement:

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

    Which worked for me. Build succeeded and produced a statically linked program.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable