我有一些C ++代码,我想从python调用。到目前为止,我将所有C ++代码放在一个文件中,并且有一个.pyx
文件对应于该代码。那么就说我的C ++文件test_A.cpp
看起来像这样
struct test{
float x;
}
并在我的test_A.pyx
文件中
cdef extern from "test_A.cpp"
cdef cppstruct test:
float x
和我的setup.py
文件看起来像
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
extensions = [Extension("test_A", ["test_A.pyx"],
include_dirs=[np.get_include()],
extra_compile_args=["-std=c++11"],
extra_link_args=[],
language="c++")]
setup(ext_modules = cythonize(extensions))
这应该可行,但现在我想拆分我的文件以获得更好的可读性,我无法弄清楚如何编译代码。现在说我有test_B.cpp
test_A.cpp
#include "test_B.h"
struct test{
test x;
test_B y;
}
我现在如何修改setup.py
文件,使其编译test_A.cpp
,然后编译并链接test_B.cpp
以及从test_a.cpp
调用的所有函数?我是否必须为.pyx
写一个第二个test_B.cpp
文件?
由于