swig 的簡單使用

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\
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章