我在将 C++ 动态库导入 Python 时遇到了一些问题

问题描述 投票:0回答:0

我用 C++ 创建了一个动态库的例子

#include <iostream>

extern "C" {

    void TaylorSeries(int x1, int x2, int delta_x, double E) {

        std::cout << x1 << x2 << std::endl;

    }

}


使用命令“g++ -shared -fPIC -o lib.so lib.cpp”和“g++ -shared -o lib.dll lib.cpp”从这个 .cpp 文件动态库创建,然后导入到 Python 文件

from ctypes import cdll

lib = cdll.LoadLibrary('./lib.so') 

lib.TaylorSeries(1, 3, 1, 1.0) 


我得到一个错误“lib.TaylorSeries(1, 3, 1, 1.0) # 从库中调用 hello 函数 ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^ ctypes.ArgumentError: 参数 4: TypeError: 不知道如何转换参数 4"

第一次接触动态库不知道怎么解决

我不知道如何让 python 理解 C++ 中的双精度类型

python c++ dll
© www.soinside.com 2019 - 2024. All rights reserved.