Generate DLL files that can be called by Python using VC

Source: Internet
Author: User

The premise already has. C and. I files

Compiled a. i file with Swid generates a WRAP.C file and a. py file

VC Create DLL Project

Add. h to the header file. c files and wrap.c files add the. i file to the project directory in the source file
Tools->options-> Modify include and Lib in directories add Python include and Libs
copy \libs\python27.lib and rename to Python27_d.lib
Modify Pyconfig.h (I only modified the previous two without modification and succeeded)
#ifdef _DEBUG
# define Py_debug
#endif
for #ifdef _DEBUG
//# define Py_debug
#end If
Modify
# ifdef _DEBUG
# pragma comment (lib, "Python24_d.lib")
# Else
# pragma comment (lib, "Python24.lib"
# endif/* _DEBUG * *
for
# ifdef _DEBUG
# pragma comment (lib, "Python24.lib")
# Else
# pragma commen T (Lib, "Python24.lib")
# endif/* _DEBUG * *
Modify object.h
Modify
#if defined (py_debug) &&!defined (py_ trace_refs)
#define PY_TRACE_REFS
#endif
to
#if defined (py_debug) &&!defined (py_trace_refs)
//#define PY_TRACE_REFS
#endif
Change the generated name.dll file to _name.pyd put the preceding. Py and _name.pyd files in a file (only. pyd files are available when I try)
Create a new test file:
Import name
AA = name.somefunction ()
Print (AA)

Generate DLL files that can be called by Python using VC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.