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

huangapple go评论64阅读模式
英文:

Adding gokogiri dependency causes `Killed: 9` exit

问题

我正在使用的环境是在MacOS Sierra上的go1.8

代码如下:

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的README时,我看到了关于安装libxml2的说明。所以我执行了brew install libxml2,但问题仍未解决。

英文:

The environment I am using is go1.8 on MacOS Sierra.

The code:

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())
	}
}

After I build and run:

$ ./hello-world
Killed: 9

Even the hello world message is not printed. Later on, on investigating the gokogiri README, I saw instructions on installing libxml2. So I did brew install libxml2 and tried, and that also did not fix the issue.

答案1

得分: 1

根据类似问题Golang问题#19734的说法,在从Apple进行C工具链(Xcode 8.3)更新后,cgo命令在darwin上失效。

解决方法是:升级到go1.8.1或更高版本,或者在buildtest命令中添加-ldflags=-s,例如go build -ldflags=-s

英文:

According to similar issue, and also in Golang issue #19734, cgo command broken on darwin after performing c tool-chain (Xcode 8.3) update from Apple.

The solution: upgrade to go1.8.1 or above or add -ldflags=-s to build or test command, e.g. go build -ldflags=-s.

huangapple
  • 本文由 发表于 2017年6月13日 12:46:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/44512577.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定