【问题标题】:mingw32-gcc compiling Cython output: unknown multiarch location for pyconfig.h (and other warnings)mingw32-gcc 编译 Cython 输出:pyconfig.h 的未知多架构位置(和其他警告)
【发布时间】:2020-03-19 11:52:49
【问题描述】:

我正在尝试为 Linux 和 Windows 制作我的 python 应用程序的可执行文件,但 Windows 构建过程失败。

这是我的 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

all 中没有提到compile-w32,因为我还没有使用它,我打算稍后尝试。)

当我尝试编译代码时,这是 makefile/mingw32-gcc 输出。 linux版本编译没有任何问题(我已经运行过一次并且运行良好),但是windows x86_64显示了很多错误和警告:

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

我已经尝试过this page(使用CFLAGS)的解决方案,但没有成功。

如果需要,其余代码(包括 main.py 文件)为here.

【问题讨论】:

    标签: python c gcc mingw mingw-w64


    【解决方案1】:

    您不能将 /usr/include/usr/lib(64) 与 MinGW 一起使用。这些位置包含为您的 Linux 系统配置和编译的软件。

    相反,当使用 MinGW for Windows 交叉编译应用程序时,您需要编译并链接到为 Windows 构建的库。

    一些 Linux 发行版可能包含一个包 mingw64-python3-devel(或类似的),其中包含必要的 Python 头文件和库文件。如果您的发行版不提供这种包,您需要自己使用 MinGW 编译 Python。 编辑:显然,使用 MinGW 交叉编译 Python 本身是 no longer supported .

    【讨论】:

    • 在哪里可以找到带有 MinGW 的 Python?我在 Ubuntu 19.10 上(忘了提,对不起),我在 apt 上找不到任何相关的东西。我也很难在 Google 上找到任何东西......
    • 那么...有没有办法将 Cython 代码编译到 Windows(通过 Linux)?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多