go 1.10:无法在共享库中隐式包含运行时/cgo

我正在尝试执行go build -buildmode=shared -linkshared test,但收到错误:


go 1.10: cannot implicitly include runtime/cgo in a shared library

我该包中只有一个文件


库.go


package test

import "fmt"

func Hello() {

    fmt.Println("Hi")

}

我在运行go1.10.4 linux/amd64 的Linux 机器上


翻阅古今
浏览 174回答 2
2回答

万千封印

这个过程对我有用:$ docker run -it golang /bin/sh# cd src# mkdir test# cat << EOF > test/lib.go> package testimport "fmt"func Hello() {&nbsp; &nbsp; fmt.Println("Hi")}> > > >&nbsp;> EOF# cat test/lib.gopackage testimport "fmt"func Hello() {&nbsp; &nbsp; fmt.Println("Hi")}# go install -buildmode=shared -linkshared std# ldd /usr/local/go/pkg/linux_amd64_dynlink/libstd.so&nbsp; &nbsp; linux-vdso.so.1 (0x00007fff4093d000)&nbsp; &nbsp; libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f3454de5000)&nbsp; &nbsp; libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3454dc4000)&nbsp; &nbsp; libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3454c03000)&nbsp; &nbsp; /lib64/ld-linux-x86-64.so.2 (0x00007f3457514000)# go install -buildmode=shared -linkshared test# ldd /go/pkg/linux_amd64_dynlink/libtest.so&nbsp; &nbsp; linux-vdso.so.1 (0x00007ffddbbeb000)&nbsp; &nbsp; libstd.so => /usr/local/go/pkg/linux_amd64_dynlink/libstd.so (0x00007f82bc8cf000)&nbsp; &nbsp; libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f82bc70a000)&nbsp; &nbsp; libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f82bc705000)&nbsp; &nbsp; libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f82bc6e4000)&nbsp; &nbsp; /lib64/ld-linux-x86-64.so.2 (0x00007f82bf0fc000)#&nbsp;

料青山看我应如是

问题是我没有cgo在任何地方导入。因此,这意味着不会导出任何函数,这意味着没有任何内容可以构建到库中。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go