C++ 在Cygwin上编译Boost,头在32/64位上不一致
我正在尝试编译Cygwin上的最新boost,我收到了大量类似以下的警告:C++ 在Cygwin上编译Boost,头在32/64位上不一致,c++,boost,cygwin,compiler-warnings,C++,Boost,Cygwin,Compiler Warnings,我正在尝试编译Cygwin上的最新boost,我收到了大量类似以下的警告: ...failed gcc.compile.c++ bin.v2/libs/python/build/gcc-4.9.2/release/link-static/threading-multi/object_protocol.o... gcc.compile.c++ bin.v2/libs/python/build/gcc-4.9.2/release/link-static/threading-multi/object_
...failed gcc.compile.c++ bin.v2/libs/python/build/gcc-4.9.2/release/link-static/threading-multi/object_protocol.o...
gcc.compile.c++ bin.v2/libs/python/build/gcc-4.9.2/release/link-static/threading-multi/object_operators.o
In file included from ./boost/python/detail/prefix.hpp:13:0,
from ./boost/python/object_operators.hpp:8,
from libs\python\src\object_operators.cpp:6:
./boost/python/detail/wrap_python.hpp:88:0: warning: "SIZEOF_LONG" redefined
# define SIZEOF_LONG 4
^
In file included from ./boost/python/detail/wrap_python.hpp:50:0,
from ./boost/python/detail/prefix.hpp:13,
from ./boost/python/object_operators.hpp:8,
from libs\python\src\object_operators.cpp:6:
/usr/include/python2.7/pyconfig.h:1013:0: note: this is the location of the previous definition
#define SIZEOF_LONG 8
我使用的是64位系统。h正确,long的大小应该是8。boost中的wrap_python.hpp有错误
我查看了wrap_python.hpp并发现:
//
// Some things we need in order to get Python.h to work with compilers other
// than MSVC on Win32
//
#if defined(_WIN32) || defined(__CYGWIN__)
# if defined(__GNUC__) && defined(__CYGWIN__)
# define SIZEOF_LONG 4
…这将导致此错误:
In file included from /usr/include/python2.7/Python.h:58:0,
from ./boost/python/detail/wrap_python.hpp:142,
from ./boost/python/detail/prefix.hpp:13,
from ./boost/python/converter/registrations.hpp:8,
from libs\python\src\object\function_doc_signature.cpp:9:
/usr/include/python2.7/pyport.h:886:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
^
如何使所有内容都是64位的 要正确编译,只需更改
#if defined(_WIN32) || defined(__CYGWIN__)
# if defined(__GNUC__) && defined(__CYGWIN__)
# define SIZEOF_LONG 4
到
在/boost/python/detail/wrap_python.hpp文件中。
根据Cygwin-64和GCC-4.9.3进行测试。
另见。
也许您已经找到了自己的解决方案,但我希望这个答案可以帮助其他人。我猜您安装了64位Cygwin。您可能需要使用-m64选项编译以选择64位构建(无法尝试:我的Cygwin是32位的,并说“对不起,未实现:64位模式未编译”),这似乎是Boost中的一个bug,wrap_python.hpp只是强制Cygwin始终为32位。或者可能我错过了一些配置选项。按照Win32约定,
long
应该始终为32位,无论您是编译32位还是64位应用程序。如果需要64位值,则需要long
。如果编译器正在执行其他操作,则它不支持Win32。(从技术上讲,必须始终为32位的类型是LONG
——如果编译器决定LONG
和LONG
是不同的类型,则您需要小心不要将它们混淆。)Cygwin在64位时不遵守Win32约定:。这使得东西更容易移植,就像在我的例子中:)
#if defined(_WIN32) || defined(__CYGWIN__)
# if defined(__GNUC__) && defined(__CYGWIN__)
# define SIZEOF_LONG 8