Cython, C++ and gsl
Cython, C++ and gsl
所以我用class.cpp class.h设置了一个c ++类.class.cpp使用了gsl的一些函数(它有#include <gsl/gsl_blas.h>
)我将其链接到另一个 c++ 文件主文件没有问题.cpp我可以编译它
g++ -o main main.o class.o -I/home/gsl/include -lm -L/home/gsl/lib -lgsl -lgslcblas
此外,在没有在class.cpp中包含gsl库的情况下,我设法创建了一个cython文件,该文件在class.cpp中使用我的类,并且可以工作。
但是,当我尝试将这两者结合起来时(即在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
依赖项。
根据您的需求进行自定义,但它应该以这种方式工作。
希望这能有所帮助...
您可以使用
Extension
类的libraries
、include_dirs
和library_dirs
参数指定所需的外部库。例如:
from distutils.extension import Extension
from distutils.core import setup
from Cython.Build import cythonize
import numpy
myext = Extension("myext",
sources=['myext.pyx', 'myext.cpp'],
include_dirs=[numpy.get_include(), '/path/to/gsl/include'],
library_dirs=['/path/to/gsl/lib'],
libraries=['m', 'gsl', 'gslcblas'],
language='c++',
extra_compile_args=["-std=c++11"],
extra_link_args=["-std=c++11"])
setup(name='myproject',
ext_modules=cythonize([myext]))
在这里,C++类在 myext.cpp
中定义,cython 接口在 myext.pyx
中定义。另请参阅:Cython 文档
相关文章:
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 为什么 Clang 不允许"and"作为函数名称?
- 如何处理来自核心指南检查器的关于gsl::at的静态分析警告
- 位阵列上的快速AND运算
- 是否可以在 C++03 中定义'move-and-swap idiom'等效项
- 将gsl c++程序与"英特尔MKL"链接
- BoostPython and CMake
- OpenSSL BIO and SSL_read
- C++ 警告:将新创建的 gsl::owner<> 分配给非所有者
- Gurobi GRBModel and GRBmodel in C++
- 没有额外参数的函数的 GSL 数值积分
- std::visit and std::variant usage
- SHBrowseForFolder with BIF_BROWSEFORCOMPUTER and SHGetPathFr
- Directx12 and keystrokes
- different between int **arr =new int [ n]; and int a[i][j]?
- C++ getenv and setenv
- Inference pytorch C++ with alexnet and cv::imread image
- Visual Studio 2019 C++ and std::filesystem
- Cython, C++ and gsl