Closed
Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
$ go version
go version go1.10.3 linux/amd64
Does this issue reproduce with the latest release?
I have not tried with any go1.11.x releases
What operating system and processor architecture are you using (go env
)?
$ go env
GOARCH="amd64"
GOBIN="/home/adam/go/bin"
GOCACHE="/home/adam/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/adam/go"
GORACE=""
GOROOT="/home/adam/.gvm/gos/go1.10.3"
GOTMPDIR=""
GOTOOLDIR="/home/adam/.gvm/gos/go1.10.3/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build321160569=/tmp/go-build -gno-record-gcc-switches"
What did you do?
You can find a demo, here.
// lib/lib.go
package main
import "C"
import "log"
//export myPrint
func myPrint(str *C.char) {
gStr := C.GoString(str)
log.Println(gStr)
}
func main() {}
//main.go
package main
//#include <stdlib.h>
//#include "./lib/lib.h"
import "C"
import "unsafe"
func main() {
cs := C.CString("hello, world!")
defer C.free(unsafe.Pointer(cs))
C.myPrint(cs)
}
$ go build -o ./lib/lib.so -buildmode=c-shared ./lib/lib.go
$ go run main.go
# command-line-arguments
In file included from ./main.go:3:0:
cgo-builtin-prolog:7:48: error: conflicting types for '_GoString_'
cgo-builtin-prolog:6:44: note: previous declaration of '_GoString_' was here
In file included from ./main.go:3:0:
cgo-gcc-export-header-prolog:27:20: error: 'GoString' redeclared as different kind of symbol
cgo-builtin-prolog:8:12: note: previous declaration of 'GoString' was here
What did you expect to see?
$ go build -o ./lib/lib.so -buildmode=c-shared ./lib/lib.go
$ go run main.go
hello, world!
What did you see instead?
$ go build -o ./lib/lib.so -buildmode=c-shared ./lib/lib.go
$ go run main.go
# command-line-arguments
In file included from ./main.go:3:0:
cgo-builtin-prolog:7:48: error: conflicting types for '_GoString_'
cgo-builtin-prolog:6:44: note: previous declaration of '_GoString_' was here
In file included from ./main.go:3:0:
cgo-gcc-export-header-prolog:27:20: error: 'GoString' redeclared as different kind of symbol
cgo-builtin-prolog:8:12: note: previous declaration of 'GoString' was here