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 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振