在 msys2-mingw 上使用 Python/C API

use Python/C API on msys2-mingw

本文关键字:API Python msys2-mingw      更新时间:2023-10-16

我尝试在msys2-mingw上使用Python/C API,所以我安装了这个包mingw-w64-x86_64-python2,我写main.cpp

#include <python2.7Python.h>
int main(){
    return 0;
}

当我进入这个$ g++ main.cpp -o main时,它给了我这些味精:

In file included from msys64mingw64include/python2.7Python.h:58:0,
             from main.cpp:1:
msys64mingw64include/python2.7pyport.h:907:2: 錯誤:#error "LONG_BIT       definition appears wrong for platform (bad gcc/glibc config?)."
 #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
  ^
In file included from msys64mingw64include/python2.7Python.h:8:0,
             from main.cpp:1:
/usr/include/cygwin/types.h:78:20: 錯誤:一個宣告指定了多個類型
 typedef __uint32_t uid_t;
                ^
/usr/include/cygwin/types.h:78:20: 錯誤:沒有宣告任何東西 [-fpermissive]
/usr/include/cygwin/types.h:84:20: 錯誤:一個宣告指定了多個類型
 typedef __uint32_t gid_t;
                ^
/usr/include/cygwin/types.h:84:20: 錯誤:沒有宣告任何東西 [-fpermissive]
makefile:2: recipe for target 'main' failed
make: *** [main] Error 1

我不知道为什么会发生这种情况。这不是关于linking file的错误(因为我没有链接任何文件。我的方法有误,还是包含错误的文件?

你混合了GCC:mingw-w64 GCC和msys GCC。对于 MSYS2 下的 mingw-w64 GCC,您不得包含来自/usr 的内容。查看您的错误消息/usr/include/cygwin/types.h