python - 错误: "Undefined Reference to" - Compile C extension for Python using Anaconda

标签 python c gcc anaconda

我在 64 位 Windows 服务器上遇到以下问题:

我有一个声明 Python 扩展的 .c 文件。使用以下命令将 .c 文件编译为 .o 文件

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

现在,.o 文件已创建,一切正常。但是当我尝试创建 .py 文件时,我收到下面的错误响应。

我的理解是,在我的 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

最佳答案

我能够解决这个问题。问题是上面提到的函数是在我的头文件中向前声明的,但函数的主体是在使用这些相同头文件的单独源文件中声明的。我将函数体复制到源文件中,一切正常

关于python - 错误: "Undefined Reference to" - Compile C extension for Python using Anaconda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37491158/

相关文章:

python - 如何在Python中随机打印列表中的元素?

python - pandas 映射带有函数的字符串列

python - 属性错误: module 'ssl' has no attribute 'PROTOCOL_TLSv1_3'

python - 如何在 Python 中查找线程的运行时间

对 Winapi 路径和文件名的说明(W 函数和 A 函数)

c - 针对动态/静态/增量数据的专用哈希表算法

c - C 到毫秒是否有替代 sleep 功能?

c - OpenMp 运算符 != 的无效控制谓词

C++ 转换运算符与构造函数优先级,编译器不同

c - 访问 C 文件中的汇编宏函数/指令