YohananDiamond
YohananDiamond

Reputation: 15

mingw32-gcc compiling Cython output: unknown multiarch location for pyconfig.h (and other warnings)

I am trying to make executables of my python application for Linux and Windows, but the Windows build process is failing.

Here is my Makefile:

all: transpile compile-linux compile-w64

transpile: main.py
    cython --embed -3 -o main.c main.py

compile-linux: main.c
    gcc -I/usr/include/python3.7 -o main main.c -lpython3.7m -lpthread -lm -lutil -ldl

compile-w32: main.c
    i686-w64-mingw32-gcc -o main-x86.exe main.c -lpython3.7m -lpthread -lm -lutil -ldl -I/usr/include/python3.7m

compile-w64: main.c
    x86_64-w64-mingw32-gcc -o main-x64.exe main.c -lpython3.7m -lpthread -lm -lutil -ldl -I/usr/include/python3.7m

(compile-w32 is not mentioned in all because I'm not using it yet, and I was going to try it later.)

When I try to compile the code, this is the makefile/mingw32-gcc output. The linux version is compiled without any problem (I've ran it already once and it worked well), but the windows x86_64 shows a lot of errors and warnings:

cython --embed -3 -o main.c main.py
gcc -I/usr/include/python3.7 -o main main.c -lpython3.7m -lpthread -lm -lutil -ldl
x86_64-w64-mingw32-gcc -o main-x64.exe main.c -lpython3.7m -lpthread -lm -lutil -ldl -I/usr/include/python3.7m
In file included from /usr/include/python3.7m/Python.h:8,
                 from main.c:4:
/usr/include/python3.7m/pyconfig.h:104:3: error: #error unknown multiarch location for pyconfig.h
  104 | # error unknown multiarch location for pyconfig.h
      |   ^~~~~
In file included from /usr/include/python3.7m/pyport.h:4,
                 from /usr/include/python3.7m/Python.h:63,
                 from main.c:4:
/usr/include/python3.7m/pyconfig.h:104:3: error: #error unknown multiarch location for pyconfig.h
  104 | # error unknown multiarch location for pyconfig.h
      |   ^~~~~
In file included from /usr/include/python3.7m/pymath.h:4,
                 from /usr/include/python3.7m/Python.h:86,
                 from main.c:4:
/usr/include/python3.7m/pyconfig.h:104:3: error: #error unknown multiarch location for pyconfig.h
  104 | # error unknown multiarch location for pyconfig.h
      |   ^~~~~
In file included from /usr/include/python3.7m/pytime.h:5,
                 from /usr/include/python3.7m/Python.h:87,
                 from main.c:4:
/usr/include/python3.7m/pyconfig.h:104:3: error: #error unknown multiarch location for pyconfig.h
  104 | # error unknown multiarch location for pyconfig.h
      |   ^~~~~
In file included from /usr/include/python3.7m/Python.h:99,
                 from main.c:4:
/usr/include/python3.7m/unicodeobject.h:68:2: error: #error Must define SIZEOF_WCHAR_T
   68 | #error Must define SIZEOF_WCHAR_T
      |  ^~~~~
In file included from /usr/include/python3.7m/pystate.h:11,
                 from /usr/include/python3.7m/traceback.h:8,
                 from /usr/include/python3.7m/Python.h:119,
                 from main.c:4:
/usr/include/python3.7m/pythread.h:122:5: error: #error "Require native threads. See https://bugs.python.org/issue31370"
  122 | #   error "Require native threads. See https://bugs.python.org/issue31370"
      |     ^~~~~
/usr/include/python3.7m/pythread.h:131:5: error: unknown type name ‘NATIVE_TSS_KEY_T’
  131 |     NATIVE_TSS_KEY_T _key;
      |     ^~~~~~~~~~~~~~~~
In file included from /usr/include/python3.7m/Python.h:156,
                 from main.c:4:
/usr/include/python3.7m/fileutils.h:95:27: warning: ‘struct stat’ declared inside parameter list will not be visible outside of this definition or declaration
   95 | #  define _Py_stat_struct stat
      |                           ^~~~
/usr/include/python3.7m/fileutils.h:100:12: note: in expansion of macro ‘_Py_stat_struct’
  100 |     struct _Py_stat_struct *status);
      |            ^~~~~~~~~~~~~~~
/usr/include/python3.7m/fileutils.h:95:27: warning: ‘struct stat’ declared inside parameter list will not be visible outside of this definition or declaration
   95 | #  define _Py_stat_struct stat
      |                           ^~~~
/usr/include/python3.7m/fileutils.h:104:12: note: in expansion of macro ‘_Py_stat_struct’
  104 |     struct _Py_stat_struct *status);
      |            ^~~~~~~~~~~~~~~
/usr/include/python3.7m/fileutils.h:108:12: warning: ‘struct stat’ declared inside parameter list will not be visible outside of this definition or declaration
  108 |     struct stat *status);
      |            ^~~~
make: *** [Makefile:13: compile-w64] Error 1

I have already tried the solution from this page (which uses CFLAGS) but it didn't work.

If needed, the rest of the code (including the main.py file) is here.

Upvotes: 1

Views: 1989

Answers (1)

jacob
jacob

Reputation: 1630

You cannot use /usr/include and /usr/lib(64) with MinGW. Those locations contain software configured and compiled for your Linux system.

Instead, when cross-compiling an application with MinGW for Windows, you need to compile it with and link to libraries that were build for Windows.

Some Linux distributions may contain a package mingw64-python3-devel (or similar) with the necessary Python headers and library files. If your distribution doesn't provide a package of that kind, you need to compile Python with MinGW on your own. EDIT: Apparently, cross-compiling Python itself using MinGW is no longer supported.

Upvotes: 3

Related Questions