英文:
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或更高版本,或者在build或test命令中添加-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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论