Search code examples
pythoncwindowscygwin

How do I build a C Python Extension for Windows using Cygwin64?


To preface: my code works as I expect when compiling and running on Linux. However, this library needs to be compiled for use on a Windows machine. I looked in to a couple different options, and decided that using Cygwin to compile for Windows seemed to be the correct choice. I'm using a setup.py file with the distutils.core library and compiling using python setup.py install. When compiling on Windows in Cygwin, it fails to find pthread.h, arpa/inet.h, netinet/in.h, and sys/socket.h. I was under the impression that Cygwin came prepackaged with these headers, which is why I chose to use it. The alternative to Cygwin is putting preprocessor commands everywhere and using Windows specific libraries such as winsock2.h, which I want to avoid if at all possible. Is it possible to compile for Windows using Cygwin? If so, what have I done wrong to cause Cygwin to not recognize these headers?


Solution

  • You need to install the proper headers

    $ cygcheck -p usr/include/pthread.h
    Found 9 matches for usr/include/pthread.h
    cygwin-devel-3.0.7-1 - cygwin-devel: Core development files
    ..
    cygwin-devel-3.1.6-1 - cygwin-devel: Core development files
    ...
    

    so install the cygwin-devel package

    To check all the shared libraries needed by the built dll, you can use cygcheck

    $ cygcheck /usr/lib/python3.8/site-packages/Cython/Compiler/FlowControl.cpython-38-x86_64-cygwin.dll
    D:\cygwin64\lib\python3.8\site-packages\Cython\Compiler\FlowControl.cpython-38-x86_64-cygwin.
    dll
      D:\cygwin64\bin\cygwin1.dll
        C:\WINDOWS\system32\KERNEL32.dll
          C:\WINDOWS\system32\ntdll.dll
          C:\WINDOWS\system32\KERNELBASE.dll
      D:\cygwin64\bin\libpython3.8.dll
        D:\cygwin64\bin\cygintl-8.dll
          D:\cygwin64\bin\cygiconv-2.dll
        D:\cygwin64\bin\cyggcc_s-seh-1.dll
    

    As was built with Cygwin Python, you need also to transfer the cygwin python...