2013-02-28 12:08
浏览 75

在带有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.

int compute(int a, int b);

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

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

%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 (

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.


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题