dry69034 2013-02-28 12:08
浏览 78
已采纳

在带有Visual Studio的Windows上使用swig -go

I want to use golang call c++ dll with swig on windows. (gc compiler, on Linux was successful.) But there have some problems. Here is the sample.

//sampel.h
int compute(int a, int b);

//sample.cpp
#include <iostream>
#include "sample.h"

int compute(int a, int b){
    int temp = (a+b)*(a-b);
    return temp;
}

//sample.i
%module sample

%inline %{
    #include "sample.h"
%}
int compute(int a,int b);

Now, I use this cmd to generate the wrap files:

swig -c++ -go -soname sample.dll -intgosize 64 sample.i

Then create an empty dll project in VS, add sample.h too Header Files, add sample.cpp and sample_wrap.cxx to Source Files, add sample.i to the project.

Build Solution, generates sample.dll

Use cmd as below to generate sample.a:

go tool 6g sample.go
go tool 6c -I C:\Go\pkg\windows_amd64 sample_gc.c
go tool pack grc sample.a sample.6 sample_gc.6

Next, install sample.a(to avoid some issue), then run the test.go:

package main

import (
    "fmt"
    "sample"
)

func main() {
    fmt.Println(sample.Compute(3, 4))
}

The problem is here, when I run test.go, got the error:

adddynlib: unsupported binary format

How do I fix the problem(dll and test.go is in the same directory)? Thanks! If you need extra information that I missed, just ask.

Alex

  • 写回答

1条回答 默认 最新

  • dqjmq28248 2013-07-02 15:28
    关注

    According to SWIG Tutorial and SWIG Comparability, it works just with 32 bit versions of Windows:

    SWIG also works perfectly well under all known 32 bit versions of Windows including 95/98/NT/2000/XP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作