python setuptools 添加def文件导出函数

python插件生成的pyd文件本质上就是dll文件,所以我们可以定义其他导出函数,__stdcall可以用def文件改名字

DWORD __stdcall test(POB_THIS obthis,int n);

pb中调用

function string test(String pbver, String commline,...) system library "E:\Python34\lib\site-packages\sample-0.0.0-py3.4-win32.egg\sample.pyd" alias for "test"

setup.py完整代码如下:

# setup.py
from setuptools import setup, Extension
mod_name = "sample"
def_ = '''LIBRARY
EXPORTS
test
'''
with open(mod_name + ".def","w") as f:
  f.write(def_)

setup(name=mod_name, ext_modules=[
    Extension(
      mod_name,
      ["{}.cpp".format(mod_name)],
      include_dirs = ['..'],
      extra_link_args=['/DEF:"{}.def"'.format(mod_name)],
    )
  ]
)

你可能感兴趣的:(python,pb,python,开发语言)