如何在 Linux for Windows 上通过 MinGW 构建静态 ICU 的 Boost

How to build Boost with static ICU via MinGW on Linux for Windows

本文关键字:构建 MinGW 静态 ICU Boost Linux for Windows      更新时间:2023-10-16

我想在 Docker Linux 映像中使用 MinGW for Windows 构建 C++ Boost 库。对于libzbz2xzzstdICU这已经有效,并安装了相应的文件。一切都是静态链接的。

文件系统结构如下所示:

$ ls -l /mingw/
drwxr-xr-x 1 root root 4096 Feb  2 00:09 include
drwxr-xr-x 1 root root 4096 Feb  2 00:09 lib
drwxr-xr-x 5 root root 4096 Feb  2 00:09 share
$ ls -l /mingw/lib/
drwxr-xr-x 3 root root     4096 Feb  2 00:09 icu
-rw-r--r-- 1 root root   371114 Feb  1 19:58 libbz2.a
-rw-r--r-- 1 root root  1940512 Feb  2 00:03 liblzma.a
-rwxr-xr-x 1 root root      876 Feb  2 00:03 liblzma.la
-rwxr-xr-x 1 root root      736 Feb  2 00:09 libsicudt.a
-rwxr-xr-x 1 root root 10895028 Feb  2 00:09 libsicuin.a
-rwxr-xr-x 1 root root   143990 Feb  2 00:09 libsicuio.a
-rwxr-xr-x 1 root root  5196448 Feb  2 00:09 libsicuuc.a
-rw-r--r-- 1 root root   118758 Feb  1 18:15 libz.a
-rw-r--r-- 1 root root   850738 Feb  1 21:11 libzstd.a
drwxr-xr-x 1 root root     4096 Feb  2 00:09 pkgconfig
$ ls -l /mingw/include/
-rw-r--r-- 1 root root   6240 Feb  1 19:58 bzlib.h
-rw-r--r-- 1 root root   4569 Nov  4 17:54 cover.h
drwxr-xr-x 2 root root   4096 Feb  2 00:03 lzma
-rw-r--r-- 1 root root   9817 Feb  2 00:03 lzma.h
drwxr-xr-x 2 root root   4096 Feb  2 00:09 unicode
-rw-r--r-- 1 root root  11500 Nov  4 17:54 zbuff.h
-rw-rw-r-- 1 root root  16298 Jan 15  2017 zconf.h
-rw-r--r-- 1 root root  17203 Nov  4 17:54 zdict.h
-rw-rw-r-- 1 root root  96239 Jan 15  2017 zlib.h
-rw-r--r-- 1 root root 119972 Nov  4 17:54 zstd.h
-rw-r--r-- 1 root root   3751 Nov  4 17:54 zstd_errors.h

我还创建了一个site-config.jam文件,b2通过它找到了libzbz2xzzstd

$ more /etc/site-config.jam 
using gcc : : x86_64-w64-mingw32-g++ : 
<cxxflags>-DBOOST_ASIO_HAS_STD_STRING_VIEW
<cxxflags>-DBOOST_ASIO_HAS_STD_IOSTREAM_MOVE
<cxxflags>--sysroot=/mingw
<cxxflags>-std=c++17 ;
using zlib : : <include>/mingw/include <search>/mingw/lib ;
using bzip2 : : <include>/mingw/include <search>/mingw/lib ;
using lzma : : <include>/mingw/include <search>/mingw/lib ;
using zstd : : <include>/mingw/include <search>/mingw/lib ;

不幸的是,这在ICU是不可能的。使用-sICU_PATH也不起作用。

我当前要构建的命令行是:

$ cd /mnt/boost_1_72_0
$ ./b2 toolset=gcc variant=release threading=multi link=static 
target-os=windows architecture=x86 address-model=64 abi=ms binary-format=pe 
-sICU_PATH=/mingw/lib 
--layout=system --prefix=/install 
--without-python --without-graph_parallel --without-mpi 
-j $(nproc) install

这将打印:

Performing configuration checks
- default address-model    : 64-bit
- default architecture     : x86
- C++11 mutex              : yes
[...]
- has_icu builds           : no
- zlib                     : yes
- bzip2                    : yes
- lzma                     : yes
- zstd                     : yes
- lzma                     : yes
- has_lzma_cputhreads builds : yes
- iconv (libc)             : no
- iconv (separate)         : no
- icu                      : no
- icu (lib64)              : no
- native-atomic-int32-supported : yes
- message-compiler         : no
- native-syslog-supported  : no
- pthread-supports-robust-mutexes : no
- compiler-supports-ssse3  : yes
- compiler-supports-avx2   : yes
- gcc visibility           : yes
- long double support      : yes
- libbacktrace builds      : no
- addr2line builds         : no
- WinDbg builds            : no
- WinDbgCached builds      : no
- BOOST_COMP_GNUC >= 4.3.0 : yes
[...]

您可以通过我的测试 Docker 映像运行并重现它:

$ docker run -it --rm bebuch/boost-with-static-icu-prepared:latest

我必须更改什么才能使icub2运行中切换到yes

编辑2020-02-03:部分答案是 Boost 1.73.0 中修复的错误:

  • https://github.com/boostorg/regex/issues/78
  • https://github.com/boostorg/regex/commit/3b98dc901a589f7a50b336aa4573743e5f5a732c

主要问题是 Boost.Regex 1.72.0 构建配置中的两个错误。

  • https://github.com/boostorg/regex/issues/78
    • 由 https://github.com/boostorg/regex/commit/3b98dc901a589f7a50b336aa4573743e5f5a732c 修复
  • https://github.com/boostorg/build/issues/529
    • 通过设置文件系统链接的解决方法

修复/解决方法后,构建成功:

./b2 toolset=gcc variant=release threading=multi link=static 
target-os=windows architecture=x86 address-model=64 abi=ms binary-format=pe 
include=/mingw/include library-path=/mingw/lib 
define=U_DISABLE_VERSION_SUFFIX=1 
--layout=system --prefix=/install 
--without-python --without-graph_parallel --without-mpi 
-j $(nproc) install

需要includelibrary-path才能查找头文件和库。这也使site-config.jam文件的最后 4 行过时。

U_DISABLE_VERSION_SUFFIX=1是必需的,因为我的 ICU 内部版本不使用此功能。没有它,您可能会收到链接器错误,例如undefined reference toucol_open_65/ucol_close_65.这些函数在我的 ICU 静态库中被命名为ucol_open/ucol_close