Compiling issues using gcc on Cython .c file

704 views
Skip to first unread message

Shuangyi Li

unread,
Dec 7, 2021, 3:18:07 PM12/7/21
to cython-users

Win 10,

python3.10

I'm new to cython, and I'm trying to use Cython to convert . py files into . c files and make . c files compile and run independently.
The contents of the. py file is:


print("hello")


I used


cython hello.py --embed


to get the .c file.

Then,


gcc hello.c -I C:......\Python\Python310\include -L C:......\Python\Python310\libs\python310.lib -fPIC -DMS_WIN64


to complie, but I got:

hello.c:203:41: warning: division by zero [-Wdiv-by-zero] enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; ^ hello.c:203:12: error: enumerator value for '__pyx_check_sizeof_voidp' is not an integer constant enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };

In fact, I have looked at several similar problems and tried their solutions,#2670,#3405, which are not valid for me. Maybe I missed something and I don't know the direction to solve it. Can someone remind me?

da-woods

unread,
Dec 7, 2021, 4:44:15 PM12/7/21
to cython...@googlegroups.com
I'd start by trying to work out what various values are. Make a simple C file containing:

#include <Python.h>
#include <stdio.h>

int main() {
    printf("%d %d\n", SIZEOF_VOID_P, sizeof(void*));
    return 0;
}

then compile it (with the same command-line arguments as your Cython file) and then run it. One possibility is that you're using a 32 bit compiler and thus sizeof(void*) will be 4.
--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/2c7d9e36-d250-4e05-adb9-571ea62752f1n%40googlegroups.com.


Stefan Behnel

unread,
Dec 8, 2021, 2:54:14 AM12/8/21
to cython...@googlegroups.com
Shuangyi Li schrieb am 07.12.21 um 19:08:
> Win 10,
>
> python3.10
>
> I'm new to cython, and I'm trying to use Cython to convert . py files into
> . c files and make . c files compile and run independently.
> The contents of the. py file is:
>
>
> print("hello")
>
>
> I used
>
>
> cython hello.py --embed
>
>
> to get the .c file.
>
> Then,
>
>
> gcc hello.c -I C:......\Python\Python310\include -L
> C:......\Python\Python310\libs\python310.lib -fPIC -DMS_WIN64
>
>
> to complie, but I got:
> hello.c:203:41: warning: division by zero [-Wdiv-by-zero] enum {
> __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; ^
> hello.c:203:12: error: enumerator value for '__pyx_check_sizeof_voidp' is
> not an integer constant enum { __pyx_check_sizeof_voidp = 1 /
> (int)(SIZEOF_VOID_P == sizeof(void*)) };
>
> In fact, I have looked at several similar problems and tried their
> solutions,#2670 <https://github.com/cython/cython/issues/2670>,#3405
> <https://github.com/cython/cython/issues/3405>, which are not valid for me.
> Maybe I missed something and I don't know the direction to solve it. Can
> someone remind me?

Your case is exactly this ticket that you found:

https://github.com/cython/cython/issues/3405

Mixing a MSVC compiled CPython installation with a MinGW compiled extension
module is not easy. You may want to look at one of the free-of-charge
Microsoft compiler packages instead. The Wiki page linked in the ticket
would explain more details.

Stefan

Shuangyi Li

unread,
Dec 8, 2021, 3:50:12 AM12/8/21
to cython-users
Hi,

I noticed that my MinGW was indeed 32-bit, and I have replaced it with X86_ 64 and make another attempt. 
But the test result is that if - DMS_Win64 is not added, the error content is the same as that of 32-bit MinGW. If - DMS_Win64 is added, the error content becomes 

undefined reference to`__ imp_ PyType_ IsSubtype'.
undefined reference to `__imp__Py_Dealloc'.
.......
and so many similar errors.

As for the compiler you mentioned, do you mean that I should not use MinGW(gcc) to compile Cython's C file, but other compilers? I also tried to compile the C file in Visual Studio 2022. The error content are: 

E1097          unknown attribute "jitintrinsic" in stdlib.h, ctype.h, correct_math.h, correct_malloc.h.
E2254        __clrcall is valid only in C++/CLI mode in stdlib.h

Thank you!
Reply all
Reply to author
Forward
0 new messages