所以我已经用 class.cpp 和 class.h 设置了一个 c++ 类。 class.cpp 使用了 gsl 中的一些函数(它有 #include <gsl/gsl_blas.h>
)
将它链接到另一个 c++ 文件 main.cpp 没有问题,我可以用它编译它
g++ -o main main.o class.o -I/home/gsl/include -lm -L/home/gsl/lib -lgsl -lgslcblas
此外,在没有将 gsl 库包含在 class.cpp 中的情况下,我已经设法创建了一个使用我在 class.cpp 中的类的 cython 文件,并且它可以工作。
但是,当我尝试结合这两者时(即在 cython 中使用 c++ 类,其中 c++ 类使用 gsl 函数),我不知道该怎么做。我想我必须包括
I/home/gsl/include -lm -L/home/gsl/lib -lgsl -lgslcblas
安装文件中的某处,但我不知道在哪里或如何。我的 setup.py 看起来像
from distutils.core import setup
from Cython.Build import cythonize
import os
os.environ["CC"] = "g++"
os.environ["CXX"] = "g++"
setup(
name = "cy",
ext_modules = cythonize('cy.pyx'),
)
我有
# distutils: language = c++
# distutils: sources = class.cpp
在我的 .pyx 文件的开头。
感谢您的帮助!
最佳答案
我建议您在扩展中使用 extra_compile_args
选项。
我已经写了一些答案,幸运的是使用了 GSL
依赖项 here .
根据您的需要进行自定义,但它应该以这种方式工作。
希望这可以帮助...
关于c++ - Cython、C++ 和 gsl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18802003/