使用Swig从Go使用C ++类

Pradeep Raja:

我想在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上成功构建和运行。

我在窗户上缺少什么吗?

这是文件结构和内容。

主(文件夹)

  • 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"
    
Pradeep Raja:

请升级到Go 1.5。Go 1.5中解决了此问题。在Windows OS以前的Go版本中,这是已知的问题。围棋队已经固定在1.5。请查看以下线程,它将提供更多信息。

在Windows中出现SWIG错误

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章