简体   繁体   中英

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

I have the following problem on a 64-bit Windows server:

I have a .c file that declares a Python extension. The .c file compiles to a .o file, using the following command

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

Now, the .o file is created and all is well. But when I try to create the .py file, I get the error response below.

What I understand is that in my c code I call the 'not_doublevector', '__impPy_InitModule4', 'chr' and 'pyvector_to_Carrayptrs' functions.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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