c++ - Cython、C++ 和 gsl

标签 c++ python cython gsl

所以我已经用 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/

相关文章:

python - 数据复制 Cython

python - 在 cython 中指定大于 long double 的数字

c++ - 尝试使用 Boost 序列化库时出错

c++ - 尝试观察数组时调试 session 卡住

python - 重置滚动总和

python - 如何使用python计算信噪比

cython - 使用 Cython 进行复值计算

c# - 有没有找到小型开源项目的简单方法?

c++ - 我是否可以将嵌套的 lua 表作为 C 函数的参数读取?

python - 需要此正则表达式的帮助