编译用Cython与C头文件的错误 [英] Compiling Cython with C header files error

查看:685
本文介绍了编译用Cython与C头文件的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图总结一些C code。与用Cython。我看了看了应用在做这个( 1 ,的 2 ),但这些教程不说太多关于如何编译$ C $ ç一旦你用用Cython包好,所以我有一个错误说,它不能找到我的C code。

So I'm trying to wrap some C code with Cython. I read read applied Cython's tutorials on doing this (1, 2), but these tutorials do not say much on how to compile the code once you have wrapped it with Cython, and so I have an error saying it can't find my C code.

首先,我用Cython脚本(calcRMSD.pyx):

First, my cython script ("calcRMSD.pyx"):

import numpy as np
cimport numpy as np

cdef extern from "rsmd.h":
    double rmsd(int n, double* x, double* y)

#rest of the code ommited

的C code,我试图总结(rmsd.h):

The C code I am trying to wrap ("rmsd.h"):

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

extern "C" {
  // svd from lapack
  void dgesvd_(char*,char*,int*,int*,double*,int*,double*,double*,int*,double*,
           int*,double*,int*,int*);
}

double rmsd(int n, double* x, double* y)
{
   //code omitted
}

Setup.py

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


setup(
    ext_modules = cythonize([Extension("calcRMSD", 
                            sources = ["calcRMSD.pyx"],
                            include_dirs = [np.get_include()],
                            libraries = ["dgesvd"]
                            #extra_compile_args = ["-I."],
                            #extra_link_args = ["-L./usr/lib/liblapack.dylib"]
                            )])

) 

我的错误:

calcRMSD.c:269:10: fatal error: 'rsmd.h' file not found
#include "rsmd.h"

我看到这个堆栈溢出线程
<一href=\"http://stackoverflow.com/questions/16993927/using-cython-to-link-python-to-a-shared-library\">Using用Cython要链接的Python到共享库

但下面这给了我不同的错误。如果我试图把rmsd.h在来源,它说,它不识别该文件类型。

but following it gives me different errors. If I try to put rmsd.h in sources, it says it doesnt recognize the file type.

<一个href=\"http://stackoverflow.com/questions/14951798/how-to-link-custom-c-which-itself-needs-special-linking-options-to-compile-wit?rq=1\">How定制C(这本身就需要特殊的链接选项编译)与用Cython链接?

这看起来有点前途但林不知道如何使用它。

This looks somewhat promising but im not sure how to use it.

请帮帮忙!

推荐答案

所有它找到包含文件首先, rsmd.h 。您需要添加在哪里这个头,可以发现到 include_dirs 参数的路径。有关丢失文件的错误应该消失。

First of all it has to find the include file, rsmd.h. You need to add the path where this header can be found to the include_dirs parameter. The error about the missing file should disappear.

然后你还需要包括你在编译C $ C $Ç得到库。如果这是 librsmd.a 将添加'RSMD 参数。此外,您可能需要包含在那里的图书馆可以找到路径的 library_dirs 参数。

Then you will additionally need to include the library you get from compiling that C code. If that's librsmd.a you would add 'rsmd' to the libraries parameter. Additionally you might need a library_dirs parameter that contains the path where that library can be found.

这篇关于编译用Cython与C头文件的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆