2016-09-21 149 views
3

繼我的earlier question之後,現在我在嘗試從此article執行所有相同步驟時遇到此錯誤,因爲我已從Go 1.6.1升級到Go 1.7。 1(我無法回到Go 1.6.1,因爲鏈接器在嘗試編譯某些共享庫時崩潰)。不能隱式地在共享庫中包含運行時/ cgo

我做了什麼:

    ~/.go/go
  1. 安裝去(這是後來被稱爲GOROOT)。
  2. 編譯libstd.so

    GOROOT=~/.go/go GOPATH=~/tests go install -buildmode=shared -linkshared std 
    
  3. 編譯calc庫:

    GOROOT=~/.go/go GOPATH=~/tests go install -a -x -buildmode=shared -linkshared calc 
    
  4. 試圖編譯app

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

    ,並收到此錯誤:

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

我想重複這些步驟與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 

這是一個已知的錯誤嗎?是否讓共享庫支持?

回答

1

我已經能夠使工作DLL的唯一方法是使用buildmode = c-archive併爲所有我想要導出的功能編寫C樁。但是我爲此工作在Windows上,我沒有在Linux上搞這個。這是一個調查的途徑。