C++ 暴露C++;与swig一起使用的lib(在macosx中)

C++ 暴露C++;与swig一起使用的lib(在macosx中),c++,macos,go,swig,C++,Macos,Go,Swig,我尝试使用SWIG来暴露C++, 我正在这样做: swig -intgosize 64 -go example.i go tool 8g -+ example.go eval $(go env) # fill in the appropiate vars go tool 8c -I ${GOROOT}/pkg/${GOOS}_${GOARCH} -D _64BIT=1 -v example_gc.c go tool pack grc example.a example.8 example_gc

我尝试使用SWIG来暴露C++,

我正在这样做:

swig -intgosize 64 -go example.i
go tool 8g -+ example.go
eval $(go env) # fill in the appropiate vars
go tool 8c -I ${GOROOT}/pkg/${GOOS}_${GOARCH} -D _64BIT=1 -v example_gc.c 
go tool pack grc example.a example.8 example_gc.8
export DYLD_LIBRARY_PATH=.:$DYLD_LIBRARY_PATH
g++ -O2 -fPIC -march=nocona -c example_wrap.c
g++ -O2 -fPIC -march=nocona -c example.c
gcc -shared -o example.so example_wrap.o example.o
##g++ -dynamclib example.o example_wrap.o -o example.so
go tool 8g runme.go
go tool 8l -o runme runme.8
除最后一行之外的所有行都有效,但在最后一个命令中,我得到:

  /go/simple/example.Void.Swigcptr: /go/simple/example.a(example.8): go%2ebuiltin.error.Error: redefinition
  go.importpath.runtime/cgo.(0): not defined
  type./go/simple/example.Void(0): not defined
  /go/simple/example.gclocals·3(0): not defined
  /go/simple/example.gcargs·3(0): not defined
  go.string."Swigcptr"(0): not defined
  go.string."SwigcptrVoid"(0): not defined
  go.string."example"(0): not defined
  type.*/go/simple/example.SwigcptrVoid(0): not defined
  /go/simple/example.gclocals·2(0): not defined
  /go/simple/example.gcargs·2(0): not defined
  type./go/simple/example.SwigcptrVoid(0): not defined
  /go/simple/example.gclocals·1(0): not defined
  /go/simple/example.gcargs·1(0): not defined
  /go/simple/example.gclocals·0(0): not defined
  /go/simple/example.gcargs·0(0): not defined

谢谢

如果您将
example.i
重命名为
example.swigcxx
,您能用一个简单的
go build
调用来构建包吗?由于Go 1.2,您不应该需要这些手动步骤。不幸的是,它不起作用,在Go repo中,他们在misc/swig中有一些示例,一些人评论说他们对这些最小的示例有问题,核心开发人员说它将为Go 1.3做好准备(见此)