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 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?