简体   繁体   中英

Using C++ classes from Go using Swig

I want to use C++ class from Go using swig in Windows7

When I build the project "go build main.go" I am getting following error:

c:\\..\\Temp\\go-build591352403/swtest.a(swtest_wrap.o): malformed pe file: __cgo_topofstack: invalid symbol binding 105

I am using go 1.3 32bit, gcc 4.8.1 32bit and swig 3.0 in Windows7. I see same error when I use 64bit Go and GCC in Windows7.

I am able build and run successfully on Ubuntu with 64-bit go and gcc.

Am I missing something in windows?

Here is the file structure and content.

main (folder)

  • main.go

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

swtest (folder)

  • 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" 

If you are feeling bold, the pe error on windows is fixed in Go 1.5beta1. Give it a spin! Download 1.5 beta2

Please upgrade to Go 1.5. This problem is solved in Go 1.5. It was known problem in Windows OS in prior Go versions. Go team has fixed in 1.5. Please take a look at following thread which will give more information.

Go with SWIG error in Windows

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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