简体   繁体   English

Cython:链接:致命错误LNK1181:无法打开输入文件

[英]Cython: LINK : fatal error LNK1181: cannot open input file

Have tried to follow this example " Python extensions with C libraries made easy by Cython " but I do not get it to work. 尝试遵循以下示例“ Cython简化了带有C库的Python扩展 ”,但我无法使其正常工作。 My system works with normal Cython. 我的系统可与普通Cython一起使用。 With some small changes in setup.py (have to use setuptools instead of distutils since I am using Windows). 在setup.py中进行了一些小的更改(由于我使用Windows,因此必须使用setuptools而不是distutils)。 Have made the following files: 已制作以下文件:

* cmean.h */
double mean(int, double*);


/* cmean.c */
double mean(int n, double* a)
{
  double s;
  int i;
  for (s=0., i=0; i<n; i++) s+=*(a++);
  return s/n;
}   

# m.pyx
cdef extern from "cmean.h":
    double mean(int, double*)

from stdlib cimport *
def cmean(a):
    n = len(a)
    cdef double *v
    v = malloc(n*sizeof(double))
    for i in range(n):
        v[i] = float(a[i])
    m = mean(n, v)
    free(v)
    return m


#setup.py
from setuptools import setup
from setuptools import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext

ext_modules=[Extension("lib",
    ["m.pyx"],
    library_dirs = ['.'],    
    libraries=["cmean"]
    )] # Unix-like specific

setup(
    name = "Demos",
    ext_modules = cythonize(ext_modules),
    cmdclass = {"build_ext": build_ext}
    )

Compile the cmean.c with this command: 使用以下命令编译cmean.c:

gcc  -shared cmean.c -o libcmean.so

But when I run: 但是当我跑步时:

python setup.py build_ext --inplace

I get these error messages: 我收到以下错误消息:

E:\GD\UD\Software\CythonTest\calling-c\test1>python setup.py build_ext --inplace
running build_ext
building 'lib' extension
C:\Users\trofl\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I. -IC:\Anaconda2\include -IC:\Anaconda2\PC /Tcm.c /Fobuild\temp.win32-2.7\Release\m.objm.c
C:\Users\trofl\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:. /LIBPATH:C:\ /LIBPATH:C:\Anaconda2\libs /LIBPATH:C:\Anaconda2\PCbuild /LIBPATH:C:\Anaconda2\PC\VS9.0 cmean.lib /EXPORT:initlib build\temp.win32-2.7\Release\m.obj /OUT:E:\GD\UD\Software\CythonTest\calling-c\test1\lib.pyd /IMPLIB:build\temp.win32-2.7\Release\lib.lib /MANIFESTFILE:build\temp.win32-2.7\Release\lib.pyd.manifest
LINK : fatal error LNK1181: cannot open input file 'cmean.lib'
error: command 'C:\\Users\\trofl\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\link.exe' failed with exit status 1181 

I have followed the example as good as I can. 我已尽我所能地跟随了这个例子。

UPDATE I have made a cmean.lib file as the last error message said it did not find with the help of Microsoft Visual Studio 2008 x86 tools. 更新我做了一个cmean.lib文件,因为最后一条错误消息说在Microsoft Visual Studio 2008 x86工具的帮助下找不到。 Tried to use the same flags as cython have used. 试图使用与cython相同的标志。 I have tried to read a lot abotu what this flags means, but I find a lot of it very technical: 我已经尝试了很多有关该标志含义的内容,但我发现其中很多都是非常技术性的:

cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG cmean.c

And then making the lib file with: 然后使用以下命令制作lib文件:

lib.exe lib.exe /out:cmean cmean.obj lib.exe lib.exe / out:cmean cmean.obj

But no I got this error: 但是不,我得到了这个错误:

E:\GD\UD\Software\CythonTest\calling-c\test1>python setup.py build_ext --inplace
running build_ext
building 'lib' extension
creating build
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
C:\Users\trofl\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Anaconda2\include -IC:\Anaconda2\PC /Tcm.c /Fobuild\temp.win32-2.7\Release\m.objm.c
C:\Users\trofl\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:. /LIBPATH:C:\Anaconda2\libs /LIBPATH:C:\Anaconda2\PCbuild /LIBPATH:C:\Anaconda2\PC\VS9.0 cmean.lib /EXPORT:initlib build\temp.win32-2.7\Release\m.obj /OUT:E:\GD\UD\Software\CythonTest\calling-c\test1\lib.pyd /IMPLIB:build\temp.win32-2.7\Release\lib.lib /MANIFESTFILE:build\temp.win32-2.7\Release\lib.pyd.manifest
LINK : error LNK2001: unresolved external symbol initlib
build\temp.win32-2.7\Release\lib.lib : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Users\\trofl\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\link.exe' failed with exit status 1120

I assume that I have to find out which arguments to use for visual c++ for windows in order to make the cmean.lib file in a correct format. 我假设我必须找出要用于Windows的Visual C ++的参数,以便使cmean.lib文件具有正确的格式。

I finally managed to get it to work by a very simple fix. 我终于设法通过一个非常简单的修复程序使其工作。 Have to use the same name of the library as the pyx file: 必须使用与pyx文件相同的库名称:

ext_modules=[Extension("m",
   sources = ["m.pyx"],
   library_dirs = ['.'],
   libraries=["cmean"])] # Unix-like specific

This as also stated in this post: 正如这篇文章中所述:

Cython compiled C extension: ImportError: dynamic module does not define init function Cython编译的C扩展:ImportError:动态模块未定义init函数

I also found that I can compile the cmean.c file with setuptools: 我还发现我可以使用setuptools编译cmean.c文件:

#setup.py
from setuptools import setup
from setuptools import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext

ext_modules=[Extension("m",
    ["m.pyx","cmean.c"] )] 


setup(
    name = "Demos",
    ext_modules = cythonize(ext_modules),
    cmdclass = {"build_ext": build_ext}
    )

– fossekall – fossekall

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 链接…链接:致命错误LNK1181:无法打开输入文件&#39;libgsl.a&#39; - Linking… LINK : fatal error LNK1181: cannot open input file 'libgsl.a' 链接:致命错误LNK1181:无法打开输入文件&#39;libclamav.lib&#39; - LINK : fatal error LNK1181: cannot open input file 'libclamav.lib' 错误 LNK1181:编译为 .LIB 时无法打开输入文件 - Error LNK1181: cannot open input file when compiling as .LIB 在Windows中使用C绑定构建Python包(VC90)会导致LNK1181致命错误 - Build Python package with C bindings in Windows (VC90) causes LNK1181 fatal error 链接:致命错误LNK1104:无法打开文件&#39;C:\\ Users \\ hp \\ .pyxbld \\ lib.win32-2.7 \\ gensim \\ models \\ word2vec_inner.pyd&#39; - LINK : fatal error LNK1104: cannot open file 'C:\Users\hp\.pyxbld\lib.win32-2.7\gensim\models\word2vec_inner.pyd' VisualStudio - 致命错误 LNK1168:无法打开 myfile.exe 进行写入 - VisualStudio - Fatal error LNK1168: cannot open myfile.exe for writing C MySQL错误“严重错误LNK1107:文件无效或损坏:无法在0x368处读取” - C MySQL error “fatal error LNK1107: invalid or corrupt file: cannot read at 0x368” 链接:致命错误 LNK1146:未使用选项“/MT”指定参数 - LINK : fatal error LNK1146: no argument specified with option '/MT' Visual Studio Express 2015中的LNK1104错误:无法打开.exe文件 - LNK1104 Error in Visual Studio Express 2015: Cannot open .exe file Cython致命错误:Python.h没有这样的文件或目录 - Cython Fatal Error: Python.h No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM