英文:
Using C++ classes from Go using Swig
问题
我想在Windows 7上使用swig将C++类从Go中调用,当我构建项目"go build main.go"时,出现以下错误:
c:..\Temp\go-build591352403/swtest.a(swtest_wrap.o): malformed pe file: __cgo_topofstack: invalid symbol binding 105
我正在使用32位的go 1.3、32位的gcc 4.8.1和swig 3.0在Windows 7上。当我在Windows 7上使用64位的Go和GCC时,也会出现相同的错误。
但是,我能够在Ubuntu上使用64位的go和gcc成功构建和运行。
我在Windows上漏掉了什么吗?
以下是文件结构和内容:
main(文件夹)
-
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"
英文:
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"
答案1
得分: 0
如果你感觉胆大,Windows上的pe错误已在Go 1.5beta1中修复。试试看吧!下载1.5 beta2
英文:
If you are feeling bold, the pe error on windows is fixed in Go 1.5beta1. Give it a spin! Download 1.5 beta2
答案2
得分: 0
请升级到Go 1.5。这个问题在Go 1.5中已经解决了。
在之前的Go版本中,这是Windows操作系统中已知的问题。Go团队已经在1.5中修复了这个问题。
请查看以下帖子,其中会提供更多信息。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论