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 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题