从Linux到Windows交叉编译boost 1.57的问题

Problems cross-compiling boost 1.57 from Linux to Windows

本文关键字:问题 boost 交叉编译 Linux Windows      更新时间:2023-10-16

我正在尝试将boost 1.57从64位Debian测试交叉编译到32位Windows。

Boost有交叉编译页面,这并没有多大帮助。例如,我不得不四处搜索,发现我需要用-sNO_BZIP2=1显式禁用bzip2,什么都不禁用zlib——它会自动禁用它(以前你必须指定-sNO_ZLIB=1,但现在它坏了)。

所以,经过一些尝试和错误,我得出了:

$ i686-w64-mingw32-g++ -v
Using built-in specs.
COLLECT_GCC=i686-w64-mingw32-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper
Target: i686-w64-mingw32
Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld
Thread model: win32
gcc version 4.9.1 (GCC)
$ wget http://sourceforge.net/projects/boost/files/boost/1.57.0/boost_1_57_0.7z
$ ls
boost_1_57_0.7z
$ 7z x boost_1_57_0.7z 
$ cd boost_1_57_0
$ echo "using gcc : : i686-w64-mingw32-g++ ;" > user-config.jam
$ ./bootstrap.sh
$ ./b2 -j10 --user-config=user-config.jam toolset=gcc-mingw address-model=32 binary-format=pe target-os=windows release --prefix=/usr/i686-w64-mingw32/local --without-python --without-wave -sNO_BZIP2=1

-j10用于10个并发作业,因为我有8个逻辑cpu内核。

用于32位构建的address-model=32

binary-format=pe被建议作为libs/context/src/asm/make_i386_sysv_elf_gas.S中构建失败的解决方法。

以上失败:

gcc.compile.c++ bin.v2/libs/context/build/gcc-mingw-4.9.1/release/address-model-32/binary-format-pe/link-static/target-os-windows/threading-multi/unsupported.o
libs/context/src/unsupported.cpp:7:2: error: #error "platform not supported"
 #error "platform not supported"
  ^
    "i686-w64-mingw32-g++"  -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -mthreads -m32  -DBOOST_ALL_NO_LIB=1 -DBOOST_CONTEXT_SOURCE -DNDEBUG  -I"." -c -o "bin.v2/libs/context/build/gcc-mingw-4.9.1/release/address-model-32/binary-format-pe/link-static/target-os-windows/threading-multi/unsupported.o" "libs/context/src/unsupported.cpp"
...failed gcc.compile.c++ bin.v2/libs/context/build/gcc-mingw-4.9.1/release/address-model-32/binary-format-pe/link-static/target-os-windows/threading-multi/unsupported.o...
...skipped <pbin.v2/libs/context/build/gcc-mingw-4.9.1/release/address-model-32/binary-format-pe/link-static/target-os-windows/threading-multi>libboost_context.a(clean) for lack of <pbin.v2/libs/context/build/gcc-mingw-4.9.1/release/address-model-32/binary-format-pe/link-static/target-os-windows/threading-multi>unsupported.o...
...skipped <pbin.v2/libs/context/build/gcc-mingw-4.9.1/release/address-model-32/binary-format-pe/link-static/target-os-windows/threading-multi>libboost_context.a for lack of <pbin.v2/libs/context/build/gcc-mingw-4.9.1/release/address-model-32/binary-format-pe/link-static/target-os-windows/threading-multi>unsupported.o...
...skipped <pstage/lib>libboost_context.a for lack of <pbin.v2/libs/context/build/gcc-mingw-4.9.1/release/address-model-32/binary-format-pe/link-static/target-os-windows/threading-multi>libboost_context.a...
...failed updating 1 target...
...skipped 3 targets...

在这一点上,我已经陷入困境,我不知道如何解决这个问题,谷歌似乎也没有帮助。

通过简单地禁用失败的库,我碰巧不需要

./b2 -j10 --user-config=user-config.jam toolset=gcc-mingw address-model=32 binary-format=pe target-os=windows release --prefix=/usr/i686-w64-mingw32/local --without-python --without-wave --without-context --without-coroutine --without-mpi --without-test --without-graph --without-graph_parallel -sNO_BZIP2=1

事实上,一些被禁用的图书馆可能不会失败,我只是查看了所有图书馆的列表,并禁用了那些与我所需要的完全无关的图书馆。

当然,这并不能解决将所有的boost库交叉编译到Windows的问题,如果知道如何正确地编译,那就太好了,但目前我对此感到满意。