不能隐式地在共享库中包含runtime/cgo

wvx*_*xvw 6 build shared-libraries go

下面我前面的问题,试图从这个执行所有相同的步骤时,现在我收到此错误的文章,因为我从围棋1.6.1升级到1.7.1去(我不能回去去,因为1.6.1尝试编译某些共享库时链接器崩溃.

我做了什么:

  1. 安装进去~/.go/go(后面称之为GOROOT).
  2. 编译libstd.so:

    GOROOT=~/.go/go GOPATH=~/tests go install -buildmode=shared -linkshared std
    
    Run Code Online (Sandbox Code Playgroud)
  3. 编译calc库:

    GOROOT=~/.go/go GOPATH=~/tests go install -a -x -buildmode=shared -linkshared calc
    
    Run Code Online (Sandbox Code Playgroud)
  4. 试图编译app:

    GOROOT=~/.go/go GOPATH=~/tests go build -a -x -linkshared -o app cashier
    
    Run Code Online (Sandbox Code Playgroud)

    并收到此错误:

    ~/.go/go/pkg/tool/linux_amd64/link: cannot implicitly include runtime/cgo in a shared library
    
    Run Code Online (Sandbox Code Playgroud)

我尝试CGO_ENABLED=0在环境之前重复这些步骤,但没有任何东西会以这种方式构建.给我这个错误:

imports runtime/cgo: C source files not allowed when not using cgo or SWIG: gcc_fatalf.c gcc_linux_amd64.c gcc_mmap.c gcc_util.c
Run Code Online (Sandbox Code Playgroud)

这是一个已知的错误?是否支持共享库?

Pat*_*ick 2

我能够制作工作 DLL 的唯一方法是使用 buildmode=c-archive 并为我想要导出的所有 go 函数编写 C 存根。但我是在 Windows 上工作的,所以我不必在 Linux 上搞乱这个。这是一条探索的道路。