0

I generated a C source file from my Python program with Cython. I was trying to compile it with GCC, but never succeed. The command I'm using currently is:

gcc -DSIZEOF_VOID_P=8 -DMS_WIN64 csv.c
    -I"C:\Users\rudz3\AppData\Local\Programs\Python\Python39\include"
    -L"C:\Users\rudz3\AppData\Local\Programs\Python\Python39\Lib"`   

But I get errors about undefined references like the following:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\rudz3\AppData\Local\Temp\ccA4Bj2u.o:csv.c:(.text+0x6e): undefined reference to \`__imp__Py_Dealloc'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\rudz3\AppData\Local\Temp\ccA4Bj2u.o:csv.c:(.text+0x161): undefined reference to `__imp__PyType_Lookup'
Jorengarenar
  • 2,705
  • 5
  • 23
  • 60
rudz33
  • 17
  • 4
  • https://stackoverflow.com/a/6731779/1046249 – Bill Morgan Aug 28 '21 at 23:39
  • 1
    The most common reasons for an 'undefined reference' is (1) forgetting to include a library, the -L flag on adds a path to where the linker looks for libraries, not the actual library to link (for that you must add something like `-lpython32`, (2) forgetting to add one of the object files to the linker command, and (3) forgetting to provide a definition for one of your user-defined functions. – thurizas Aug 28 '21 at 23:52
  • @thurizas i changed -L"C:\Users\rudz3\AppData\Local\Programs\Python\Python39\Lib" to -L"C:\Users\rudz3\AppData\Local\Programs\Python\Python39\libs" and added -lpython39 and almost all errors are gone. That what remains: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function \`main': C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain' collect2.exe: error: ld returned 1 exit status Maybe you know how to fix that? – rudz33 Aug 29 '21 at 01:43
  • It means you forgot a `main` function. – HolyBlackCat Aug 29 '21 at 07:18
  • Does this answer your question? [Link to Python with MinGW](https://stackoverflow.com/questions/6731100/link-to-python-with-mingw) – the busybee Aug 29 '21 at 10:09
  • @rudz33 WinMain is the entry point for a GUI application. The entry point for a console based application is main (or their wide character equivalents tmain and tWinMain, IIRC). There is a linker setting defining the subsystem that the application will use, in Visual Studio it is found at properties->linker->system->subsystem; for the Microsoft linker (link) the command line option is `/SUBSYSTEM:[native|windows|console]`. For gcc it appears that windows is the default and you can use either `-mconsole` or `-mdll` to change the subsystem – thurizas Aug 29 '21 at 12:15

0 Answers0