添加 gokogiri 依赖导致 `Killed: 9` 退出

Adding gokogiri dependency causes `Killed: 9` exit

我使用的环境是go1.8 on MacOS Sierra

代码:

package main

import (
    "fmt"
    "io/ioutil"

    "github.com/moovweb/gokogiri"
    "github.com/moovweb/gokogiri/xpath"
)

func main() {
    fmt.Println("hello world")
    b, _ := ioutil.ReadFile("x.xml")
    fmt.Println(string(b))
    doc, _ := gokogiri.ParseXml(b)
    compiled := xpath.Compile("/path/to/node")
    ss, _ := doc.Root().Search(compiled)
    for _, s := range ss {
        fmt.Println(s.Content())
    }
}

在我构建之后 运行:

$ ./hello-world
Killed: 9

甚至 hello world 消息也没有打印出来。后来,在调查 gokogiri 自述文件时,我看到了有关安装 libxml2 的说明。所以我做了 brew install libxml2 并尝试了,但也没有解决问题。

根据 similar issue, and also in Golang issue #19734,从 Apple 执行 c 工具链 (Xcode 8.3) 更新后,cgo 命令在 darwin 上损坏。

解决方法:upgrade to go1.8.1 or above或在buildtest命令中添加-ldflags=-s,例如go build -ldflags=-s.