You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# command-line-arguments
./foo.a(go.o): In function `_cgo_topofstack':
/home/reus/go/src/runtime/asm_amd64.s:2327: multiple definition of `_cgo_topofstack'
/tmp/go-build074487992/command-line-arguments/_obj/_cgo_main.o:/tmp/go-build/command-line-arguments/_obj/_cgo_main.c:5: first defined here
./foo.a(go.o): In function `_cgo_panic':
/home/reus/go/src/runtime/cgo/callbacks.go:45: multiple definition of `_cgo_panic'
/tmp/go-build074487992/command-line-arguments/_obj/_cgo_main.o:/tmp/go-build/command-line-arguments/_obj/_cgo_main.c:6: first defined here
./foo.a(go.o): In function `crosscall2':
/home/reus/go/src/runtime/cgo/asm_amd64.s:12: multiple definition of `crosscall2'
/tmp/go-build074487992/command-line-arguments/_obj/_cgo_main.o:/tmp/go-build/command-line-arguments/_obj/_cgo_main.c:2: first defined here
./foo.a(000001.o): In function `_cgo_wait_runtime_init_done':
/home/reus/go/src/runtime/cgo/gcc_libinit.c:35: multiple definition of `_cgo_wait_runtime_init_done'
/tmp/go-build074487992/command-line-arguments/_obj/_cgo_main.o:/tmp/go-build/command-line-arguments/_obj/_cgo_main.c:3: first defined here
./foo.a(000001.o): In function `_cgo_release_context':
/home/reus/go/src/runtime/cgo/gcc_context.c:11: multiple definition of `_cgo_release_context'
/tmp/go-build074487992/command-line-arguments/_obj/_cgo_main.o:/tmp/go-build/command-line-arguments/_obj/_cgo_main.c:4: first defined here
collect2: error: ld returned 1 exit status
The text was updated successfully, but these errors were encountered:
-buildmode=c-archive is designed for linking Go code into a C program. You are trying to use it to link Go code into a Go program. That can't work. That's not what it's for.
@iangudger but the below simple example doesn't work either:
$ cat mde.go
package main
/*
int Add(int i) {
return i + 1;
}
*/
import "C"
import "fmt"
func main() {
}
//export Foo
func Foo() {
fmt.Printf("Foo!\n")
C.Add(1)
}
$ go build -buildmode=c-archive mde.go
# command-line-arguments
/tmp/go-build123475493/command-line-arguments/_obj/mde.cgo2.o: In function `Add':
./mde.go:5: multiple definition of `Add'
/tmp/go-build123475493/command-line-arguments/_obj/_cgo_export.o:/data/kdr2/.../mde.go:5: first defined here
collect2: error: ld returned 1 exit status
Using //export in a file places a restriction on the preamble: since it is copied into two different C output files, it must not contain any definitions, only declarations. If a file contains both definitions and declarations, then the two output files will produce duplicate symbols and the linker will fail. To avoid this, definitions must be placed in preambles in other files, or in C source files.
What version of Go are you using (
go version
)?go version devel +c99483feb8 Sat Jun 3 17:04:56 2017 +0000 linux/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/reus"
GORACE=""
GOROOT="/home/reus/go"
GOTOOLDIR="/home/reus/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build884024617=/tmp/go-build -gno-record-gcc-switches"
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"
What did you do?
lib.go
lib.c
build static library
call.go
build call.go
What did you expect to see?
no build error
What did you see instead?
The text was updated successfully, but these errors were encountered: