我正在尝试使用 swig 与 c++ 交互,但我在使用std::string&
参数时遇到了问题。这是在带有 golang 1.1-2、swig 2.0.10-1 和 gcc 4.8.1-1 的 Fedora 19 上。
我不懂C++。我确实知道 C,并曾希望将它赐予我们。无论如何,_swig_wrap_pinput
以空指针结束。
我在看什么?
这是我的测试用例:
st.i
%module st
%{
#include <string>
extern void pinput(std::string& pstring);
%}
%include <std_string.i>
#include <string>
void pinput(std::string& pstring);
st.cxx
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
void pinput(std::string& pstring) {
std::cout<<pstring;
}
stmain.go
package main
import (
"st"
)
func main() {
myLit:="This is a test."
st.Pinput(&myLit)
}
生成文件
SWIGOBJS = st_gc.c st_wrap.cxx st.go
all: st.so st.a
$(SWIGOBJS): st.i
swig -go -c++ -intgosize 64 st.i
st.o: st.cxx
g++ -c -fpic -g -o st.o st.cxx
st_wrap.o: st_wrap.cxx
g++ -c -fpic -g -o st_wrap.o st_wrap.cxx
st.so: st_wrap.o st.o
g++ -shared st_wrap.o st.o -o st.so
st_gc.6: st_gc.c
/usr/lib64/golang/pkg/tool/linux_amd64/6c -I /usr/lib64/golang/pkg/linux_amd64 st_gc.c
st.6: st.go
/usr/lib64/golang/pkg/tool/linux_amd64/6g st.go
st.a: st.6 st_gc.6
go tool pack grc st.a st.6 st_gc.6
test: stmain
stmain: stmain.6
/usr/lib64/golang/pkg/tool/linux_amd64/6l stmain.6
stmain.6: stmain.go
/usr/lib64/golang/pkg/tool/linux_amd64/6g stmain.go