我遇到了最新的cygwin g ++ - 5.4.0和python3.4这个问题。以下简单的代码暴露了这个问题:
#include <string>
#include <Python.h>
#include <vector>
#include <map>
//#include <string>
#include <iostream>
int main(int argc, char ** argv)
{
return 0;
}
用&#34;编译后g ++ -g -O2 -std = c ++ 11 test.c -o test python3-config --includes
&#34;,我收到了以下错误:
In file included from /usr/include/python3.4m/Python.h:8:0,
from test.c:2:
/usr/include/python3.4m/pyconfig.h:1440:0: warning: "__BSD_VISIBLE" redefined
#define __BSD_VISIBLE 1
^
In file included from /usr/include/sys/config.h:5:0,
from /usr/include/_ansi.h:16,
from /usr/include/wchar.h:4,
from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/cwchar:44,
from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/postypes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/char_traits.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/string:40,
from test.c:1:
/usr/include/sys/features.h:250:0: note: this is the location of the previous definition
#define __BSD_VISIBLE 0
^
In file included from /usr/include/python3.4m/pyport.h:335:0,
from /usr/include/python3.4m/Python.h:50,
from test.c:2:
/usr/include/sys/time.h:104:34: error: 'u_int' has not been declared bintime_mul(struct bintime *_bt, u_int _x)
一个棘手的问题是,如果我包含&#34; Python.h&#34;。编译通过。我在linux / Mac OS上没有看到这个问题。
我不认为这是一个有效的解决方案。由于代码更复杂,我在程序的最开始(在进入main函数之前)遇到段默认值。
答案 0 :(得分:2)
修改文件/usr/include/python3.4m/pyconfig.h
,替换
#define __BSD_VISIBLE 1
与
#define __BSD_VISIBLE 0