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

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

我想在 Docker Linux 图像中使用 MinGW 为 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 中修复的错误:

主要问题是 Boost.Regex 1.72.0.

构建配置中的两个错误

在 fixing/workaround 之后,构建成功:

./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 to ucol_open_65/ucol_close_65。这些函数在我的 ICU 静态库中被命名为 ucol_open/ucol_close