Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot implicitly include runtime/cgo in a shared library

Following my earlier question, now I'm getting this error when trying to perform all the same steps from this article, since I've upgraded from Go 1.6.1 to Go 1.7.1 (I cannot go back to Go 1.6.1 because the linker crashes when tries to compile some shared libraries).

What I did:

  1. Installed go in ~/.go/go (this is later referred to as GOROOT).
  2. Compiled libstd.so:

    GOROOT=~/.go/go GOPATH=~/tests go install -buildmode=shared -linkshared std
    
  3. Compiled calc library:

    GOROOT=~/.go/go GOPATH=~/tests go install -a -x -buildmode=shared -linkshared calc
    
  4. Tried to compile app:

    GOROOT=~/.go/go GOPATH=~/tests go build -a -x -linkshared -o app cashier
    

    and received this error:

    ~/.go/go/pkg/tool/linux_amd64/link: cannot implicitly include runtime/cgo in a shared library
    

I tried to repeat the steps with CGO_ENABLED=0 prepended to the environment, but nothing would build this way. Giving me this error:

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

Is this a known bug? Is making shared libraries meant to be supported?

like image 211
wvxvw Avatar asked Sep 21 '16 12:09

wvxvw


1 Answers

The only way I've been able to make working DLLs is to use buildmode=c-archive and write C stubs for all the go functions I want to export. But I was working on Windows for this, I haven't had to mess with this on Linux. It is a path to investigate.

like image 77
Patrick Avatar answered Oct 15 '22 06:10

Patrick