Missing Python.h while trying to compile a C extension module

前端 未结 3 1403
灰色年华
灰色年华 2020-12-10 05:17

I\'m following this tutorial on how to extend Python with C\\C++ code.

The section named \"Building the extension module with GCC for Microsoft Windows\" fails for m

3条回答
  •  既然无缘
    2020-12-10 05:39

    The Python official documentation has already made it clear. Check it out here

    The header files are typically installed with Python. On Unix, these are located in the directories prefix/include/pythonversion/ and exec_prefix/include/pythonversion/, where prefix and exec_prefix are defined by the corresponding parameters to Python’s configure script and version is '%d.%d' % sys.version_info[:2]. On Windows, the headers are installed in prefix/include, where prefix is the installation directory specified to the installer.

    To include the headers, place both directories (if different) on your compiler’s search path for includes. Do not place the parent directories on the search path and then use #include ; this will break on multi-platform builds since the platform independent headers under prefix include the platform specific headers from exec_prefix.

    And they have provided a convenient way to get the correct cflags that we should pass to compiler. here

    So for example, here is what I got after running the command

    root@36fd2072c90a:/# /usr/bin/python3-config --cflags
    -I/usr/include/python3.5m -I/usr/include/python3.5m  -Wno-unused-result -Wsign-compare -g -fstack-protector-strong -Wformat -Werror=format-security  -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
    

    Pass those flags to the compiler, and it will work.

提交回复
热议问题