简体   繁体   English

错误:“未定义引用”-使用Anaconda为Python编译C扩展

[英]Error: “ Undefined Reference to” - Compile C extension for Python using Anaconda

I have the following problem on a 64-bit Windows server: 我在64位Windows服务器上遇到以下问题:

I have a .c file that declares a Python extension. 我有一个.c文件,它声明一个Python扩展名。 The .c file compiles to a .o file, using the following command 使用以下命令,.c文件将编译为.o文件

gcc -c chr.c -IC:\Anaconda\include -o chr.o

Now, the .o file is created and all is well. 现在,创建了.o文件,一切顺利。 But when I try to create the .py file, I get the error response below. 但是,当我尝试创建.py文件时,出现以下错误响应。

What I understand is that in my c code I call the 'not_doublevector', '__impPy_InitModule4', 'chr' and 'pyvector_to_Carrayptrs' functions. 我的理解是,在我的C代码中,我将其称为“ not_doublevector”,“ __ impPy_InitModule4”,“ chr”和“ pyvector_to_Carrayptrs”函数。

gcc -shared chr.o -LC:\Anaconda\libs -lpython27 -o chr.py

chr.o:chr.c:(.text+0x1a15): undefined reference to `not_doublevector'
chr.o:chr.c:(.text+0x1a35): undefined reference to `not_doublevector'
chr.o:chr.c:(.text+0x1a89): undefined reference to `pyvector_to_Carrayptrs'
chr.o:chr.c:(.text+0x1a99): undefined reference to `pyvector_to_Carrayptrs'
chr.o:chr.c:(.text+0x1aeb): undefined reference to `chr'
chr.o:chr.c:(.text+0x1c3d): undefined reference to `__imp_Py_InitModule4'
collect2.exe: error: ld returned 1 exit status

I was able to fix this problem. 我能够解决此问题。 The issue was that the functions mentioned above were forward declared in my header files, but the body of the function was declared in a separate source file that used these same header files. 问题是上面提到的函数是在我的头文件中声明的,但是函数的主体是在使用这些头文件的单独的源文件中声明的。 I copied the function body into my source file and everything worked 我将函数主体复制到我的源文件中,一切正常

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM