【问题标题】:Using C++ classes from Go using Swig使用 Swig 从 Go 中使用 C++ 类
【发布时间】:2016-01-07 19:15:53
【问题描述】:

我想在 Windows7 中使用 swig 使用 Go 中的 C++ 类

当我构建项目“go build main.go”时,出现以下错误:

c:\..\Temp\go-build591352403/swtest.a(swtest_wrap.o):格式错误的 pe 文件:__cgo_topofstack:无效符号绑定 105

我在 Windows7 中使用 go 1.3 32bit、gcc 4.8.1 32bit 和 swig 3.0。 当我在 Windows7 中使用 64 位 Go 和 GCC 时,我看到了同样的错误。

我能够使用 64 位 go 和 gcc 在 Ubuntu 上成功构建和运行。

我在 Windows 中遗漏了什么吗?

这是文件结构和内容。

主(文件夹)

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

【问题讨论】:

    标签: c++ go swig


    【解决方案1】:

    如果您觉得大胆,Windows 上的 pe 错误在 Go 1.5beta1 中已修复。试一试!下载1.5 beta2

    【讨论】:

      【解决方案2】:

      请升级到 Go 1.5。这个问题在 Go 1.5 中得到解决。 在以前的 Go 版本中,这是 Windows 操作系统中的已知问题。 Go 团队已在 1.5 中修复。 请查看以下线程,这将提供更多信息。

      Go with SWIG error in Windows

      【讨论】:

      • 是什么原因?请问有什么解释吗?如果您没有什么要解释的,请在评论中给出此类答案:)
      猜你喜欢
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-12
      • 1970-01-01
      相关资源
      最近更新 更多