swig 的简单使用

9 篇文章 1 订阅

swig


/* File: copy2.i */
%module copy2

%{
#define SWIG_FILE_WITH_INIT
#define _CRT_SECURE_NO_WARNINGS
#include "copy2.h"
%}


int file_copy(const wchar_t* srcPath, const wchar_t* dstPath);
long long getcopysize();
int setcopysize();
  • swig -c++ -python .\copy2.i
"""
setup.py
"""
 
from distutils.core import setup, Extension
 
 
copy2_module = Extension('_copy2',
                           sources=['copy2_wrap.cxx', 'copy2.cpp'],
                           )
 
setup (name = 'copy2',
       version = '0.1',
       author      = "SWIG Docs",
       description = """Simple swig example from docs""",
       ext_modules = [copy2_module],
       py_modules = ["copy2"],
       )
  • python setup.py build

  • c++类

#ifndef FOO_H__
#define FOO_H__

class Foo
{
public:
    Foo();

    int GetNum();
    void SetNum(int num);

private:
    int m_num;
};

#endif  // FO
#include "Foo.h"

Foo::Foo()
: m_num(-1)
{

}

int Foo::GetNum()
{
    return m_num;
}

void Foo::SetNum( int num )
{
    m_num = num;
}
/* File: foo.i */
%module foo

%{
#include "Foo.h"
%}

class Foo
{
public:
    Foo();

    int GetNum();
    void SetNum(int num);

private:
    int m_num;
};
Unable to find vcvarsall.bat 错误的解决
  • 增加系统变量
VS90COMNTOOLS
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值