簡體   English   中英

錯誤:“未定義引用”-使用Anaconda為Python編譯C擴展

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

我在64位Windows服務器上遇到以下問題:

我有一個.c文件,它聲明一個Python擴展名。 使用以下命令,.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

我能夠解決此問題。 問題是上面提到的函數是在我的頭文件中聲明的,但是函數的主體是在使用這些頭文件的單獨的源文件中聲明的。 我將函數主體復制到我的源文件中,一切正常

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM