简体   繁体   English

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

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

I want to use C++ class from Go using swig in Windows7 我想在Windows7中使用Swig中的C ++类

When I build the project "go build main.go" I am getting following error: 当我构建项目“go build main.go”时,我收到以下错误:

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

I am using go 1.3 32bit, gcc 4.8.1 32bit and swig 3.0 in Windows7. 我在Windows7中使用的是1.3 32bit,gcc 4.8.1 32bit和swig 3.0。 I see same error when I use 64bit Go and GCC in Windows7. 当我在Windows7中使用64位Go和GCC时,我看到同样的错误。

I am able build and run successfully on Ubuntu with 64-bit go and gcc. 我可以使用64位go和gcc在Ubuntu上成功构建和运行。

Am I missing something in windows? 我在Windows中遗漏了什么吗?

Here is the file structure and content. 这是文件结构和内容。

main (folder) 主(文件夹)

  • main.go main.go

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

swtest (folder) swtest(文件夹)

  • swtest.cpp swtest.cpp

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

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

      package swtest 
  • swtest.swigcxx swtest.swigcxx

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

If you are feeling bold, the pe error on windows is fixed in Go 1.5beta1. 如果你感觉大胆,那么Windows的pe错误在Go 1.5beta1中得到修复。 Give it a spin! 给它一个旋转! Download 1.5 beta2 下载1.5 beta2

Please upgrade to Go 1.5. 请升级到Go 1.5。 This problem is solved in Go 1.5. 在Go 1.5中解决了这个问题。 It was known problem in Windows OS in prior Go versions. 在之前的Go版本中,Windows OS中存在已知问题。 Go team has fixed in 1.5. Go团队已经固定在1.5。 Please take a look at following thread which will give more information. 请查看以下主题,它将提供更多信息。

Go with SWIG error in Windows 在Windows中使用SWIG错误

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

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