douguomou5094 2015-02-18 08:55
浏览 78
已采纳

使用Swig从Go使用C ++类

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"
    
  • 写回答

2条回答 默认 最新

  • douwudie8060 2016-01-07 05:32
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭