目錄
1,新建一個工程
math_functions.cpp內容:
先編譯一下看是否可以正常運行:
2,編譯成dll,并用Python調用
有兩種方式:
命令 1(使用靜態鏈接):
可移植性:
命令 2(動態鏈接):
可移植性:
這里我使用的是靜態鏈接的方式:
python調用實例 test_dll.py
1,新建一個工程
math_functions.cpp內容:
#include <iostream>
#include <cstring>
#include <windows.h>#ifdef __cplusplus
extern "C" {
#endif// 定義導出宏(兼容 MinGW 和 MSVC)
#if defined(_WIN32) || defined(_WIN64)#ifdef BUILD_DLL#define DLL_EXPORT __declspec(dl