windows 环境下使用swig

我使用的是vs2008和python3.3以及swig3.0.2

例子采用swig中的simple例子

把代码贴上:

/* File : example.c */
/* A global variable */
double Foo = 3.0;

/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
  int g;
  g = y;
  while (x > 0) {
    g = x;
    x = y % x;
    y = g;
  }
  return g;
}

以下是指令文件,也称接口文件
/* File : example.i */
%module example

%inline %{
extern int    gcd(int x, int y);
extern double Foo;
%}

下面开始具体操作步骤:

1.运行cmd,找到swig.exe的目录,输入swig -python example.i 注:写明example.i的路径

运行成功后会在c文件目录下生成两个文件:example.py 和example_wrap.c

2.在vs中新建工程,将example.c 、example_wrap.c、example.i添加到工程,同时设置工程-属性-链接器-常规-输出 为$(OutDir)\_$(ProjectName).pyd

3.debug工程,会在debug目录下生成_工程名.pyd

4.将上述.pyd文件放置到example.py目录下,在idle中运行,即可使用c文件中的函数。


可以参考如下帖子:http://bbs.csdn.net/topics/300099682

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值