Python calls the C function

Source: Internet
Author: User
Tags windows x64

Yes, I started integrate another way ~ ~

This method uses C++,python as glue, for the MATLAB call, originally is compiles on the Linux to run, I need to put it on the Windows x64 to run up ~ ~

On the Linux platform, Python calls C is done in this way:

var = cdll ('test.so')

Where. So is a file on Linux called a shared library, similar to a. dll file for Windows. So take it for granted, we need to replace this file with Test.dll after Windows is called.

This step is not difficult either, by adding the keyword __declspec (dllexport) before the function declaration that needs to provide the external interface.

The sample code looks like this:

#define Dll_api __declspec (dllexport)void foo ();

When you're done, change the VS project configuration type to a dynamic library (. dll) and compile to get the Test.dll file

The statements that are called in Python are as follows:

var = cdll ('test.dll')

Now, in Python, you can happily invoke functions in C + + ~~o (^▽^) o

Python calls the C function

Related Article

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.