繁体   English   中英

使用Swig中的Go使用C ++类

[英]Using C++ classes from Go using Swig

我想在Windows7中使用Swig中的C ++类

当我构建项目“go build main.go”时,我收到以下错误:

c:\\ .. \\ Temp \\ go-build591352403 / swtest.a(swtest_wrap.o):格式错误的pe文件:__ cgo_topofstack:无效的符号绑定105

我在Windows7中使用的是1.3 32bit,gcc 4.8.1 32bit和swig 3.0。 当我在Windows7中使用64位Go和GCC时,我看到同样的错误。

我可以使用64位go和gcc在Ubuntu上成功构建和运行。

我在Windows中遗漏了什么吗?

这是文件结构和内容。

主(文件夹)

  • main.go

     package main import ( "swtest" ) func main() { swtest.NewSwt().Print("Swig test!") } 

swtest(文件夹)

  • swtest.cpp

     #include "swtest.h" void Swt::Print(const std::string& s) { std::cout << s; std::cout << std::endl; } 
  • swtest.h

      #ifndef SWTEST_H #define SWTEST_H #include <string> #include <iostream> class Swt { public: void Print(const std::string& s); }; #endif 
  • swtest.go

      package swtest 
  • swtest.swigcxx

     %module swtest %include "std_string.i" %{ #include "swtest.h" %} %include "swtest.h" 

如果你感觉大胆,那么Windows的pe错误在Go 1.5beta1中得到修复。 给它一个旋转! 下载1.5 beta2

请升级到Go 1.5。 在Go 1.5中解决了这个问题。 在之前的Go版本中,Windows OS中存在已知问题。 Go团队已经固定在1.5。 请查看以下主题,它将提供更多信息。

在Windows中使用SWIG错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM