我试图编译一个Cython程序,但我得到一个错误,试图链接LAPACK和BLAS(它找不到库)。我有Anaconda Accelerate,它会自动将MKL链接到NumPy,所以我试图复制NumPy的链接。
>>> import numpy as np
>>> np.show_config()
mkl_info:
include_dirs = ['/home/ubuntu/miniconda3/envs/LDFMap/include']
define_macros = [('SCIPY_MKL_H', None)]
libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
library_dirs = ['/home/ubuntu/miniconda3/envs/LDFMap/lib']
blas_mkl_info:
include_dirs = ['/home/ubuntu/miniconda3/envs/LDFMap/include']
define_macros = [('SCIPY_MKL_H', None)]
libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
library_dirs = ['/home/ubuntu/miniconda3/envs/LDFMap/lib']
lapack_mkl_info:
include_dirs = ['/home/ubuntu/miniconda3/envs/LDFMap/include']
define_macros = [('SCIPY_MKL_H', None)]
libraries = ['mkl_lapack95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
library_dirs = ['/home/ubuntu/miniconda3/envs/LDFMap/lib']
blas_opt_info:
include_dirs = ['/home/ubuntu/miniconda3/envs/LDFMap/include']
define_macros = [('SCIPY_MKL_H', None)]
libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
library_dirs = ['/home/ubuntu/miniconda3/envs/LDFMap/lib']
openblas_lapack_info:
NOT AVAILABLE
lapack_opt_info:
include_dirs = ['/home/ubuntu/miniconda3/envs/LDFMap/include']
define_macros = [('SCIPY_MKL_H', None)]
libraries = ['mkl_lapack95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
library_dirs = ['/home/ubuntu/miniconda3/envs/LDFMap/lib']
这是我的setup.py
文件
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
from Cython.Build import cythonize
import numpy as np
import os
setup(
author = "Rohan Pandit",
url='https://www.github.com/rohanp/LDFMap',
ext_modules = cythonize([Extension("LDFMap",
sources = ["LDFMap.pyx"],
include_dirs = [np.get_include(), "/home/ubuntu/LDFMap/src/include", "/home/ubuntu/miniconda3/envs/LDFMap/include"],
language="c++",
libraries = ['mkl_lapack95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread'],
library_dirs = ["/home/ubuntu/LDFMap/src/include", '/home/ubuntu/miniconda3/envs/LDFMap/lib'],
extra_compile_args = ["-I /home/ubuntu/LDFMap/src/include", "-I /usr/local/include"],
)])
)
,这是我的错误信息:(为了便于阅读,我添加了换行符)
g++ -pthread -shared -L/home/ubuntu/miniconda3/envs/LDFMap/lib -Wl,
-rpath=/home/ubuntu/miniconda3/envs/LDFMap/lib,--no-as-needed
build/temp.linux-x86_64-3.4/LDFMap.o -L/home/ubuntu/LDFMap/src/include
-L/home/ubuntu/miniconda3/envs/LDFMap/lib -
L/home/ubuntu/miniconda3/envs/LDFMap/lib -lmkl_lapack95_lp64 -
lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -
lpython3.4m -o /home/ubuntu/LDFMap/src/LDFMap.cpython-34m.so
/usr/bin/ld: cannot find -lmkl_lapack95_lp64
我不明白的是,如果这个链接为NumPy工作,为什么它不为我的程序工作?
明确指定安装的include路径和BLAS/LAPACK库将导致一个非常依赖于平台且难以维护的模块。
你应该做的是,使用scipy来获取你需要的LAPACK函数的指针,正如这篇文章所解释的那样(特别是第一个链接中的要点)。这样,如果Scipy与MKL一起安装,您的Cython程序也将自动使用MKL BLAS/LAPACK。