简体   繁体   English

Linux 上 Windows 的交叉编译提升

[英]Cross-compiling boost for Windows on Linux

I'm trying to create mingw binaries for boost on a Linux machine.我正在尝试为 Linux 机器上的 boost 创建 mingw 二进制文件。 The mingw compiler is present on my system as /usr/bin/i586-mingw32msvc-g++ and I have been able to create a simple HelloWorld.exe application. mingw 编译器作为 /usr/bin/i586-mingw32msvc-g++ 出现在我的系统上,我已经能够创建一个简单的 HelloWorld.exe 应用程序。

Here is an exact list of my actions:这是我的操作的确切列表:

$ tar xvf boost_1_46_1.tar.gz
$ cd boost_1_46_1/
$ echo "using gcc : 4.4.4: i586-mingw32msvc-g++ ;" > user-config.jam
$ ./bootstrap.sh
$ ./bjam toolset=gcc target-os=windows

The result is this:结果是这样的:

Building the Boost C++ Libraries.


...found 83 targets...
...updating 9 targets...
common.mkdir bin.v2
common.mkdir bin.v2/libs
common.mkdir bin.v2/libs/regex
common.mkdir bin.v2/libs/regex/build
common.mkdir bin.v2/libs/regex/build/gcc-mingw-4.4.4
common.mkdir bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug
common.mkdir bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug/target-os-windows
gcc.compile.c++ bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug/target-os-windows/has_icu_test.o
In file included from /usr/include/unicode/pwin32.h:123,
                 from /usr/include/unicode/umachine.h:47,
                 from /usr/include/unicode/uversion.h:47,
                 from libs/regex/build/has_icu_test.cpp:12:
/usr/include/inttypes.h:290: warning: ISO C++ 1998 does not support ‘long long’
/usr/include/inttypes.h:291: warning: ISO C++ 1998 does not support ‘long long’
libs/regex/build/has_icu_test.cpp: In function ‘int main()’:
libs/regex/build/has_icu_test.cpp:24: warning: unused variable ‘c’
gcc.link bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug/target-os-windows/has_icu.exe
/usr/lib/gcc/i586-mingw32msvc/4.4.4/../../../../i586-mingw32msvc/bin/ld: cannot find -licuuc
collect2: ld returned 1 exit status

    "i586-mingw32msvc-g++" -L"/usr/bin" -L"/usr/lib" -Wl,-R -Wl,"/usr/bin" -Wl,-R -Wl,"/usr/lib" -Wl,-rpath-link -Wl,"/usr/bin" -Wl,-rpath-link -Wl,"/usr/lib" -o "bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug/target-os-windows/has_icu.exe" -Wl,--start-group "bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug/target-os-windows/has_icu_test.o"  -Wl,-Bstatic  -Wl,-Bdynamic -licuuc -licui18n -licudata -Wl,--end-group -g 


...failed gcc.link bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug/target-os-windows/has_icu.exe...
...failed updating 1 target...
...updated 8 targets...
Performing configuration checks

    - has_icu builds           : no
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam
...found 8 targets...
...updating 6 targets...
common.mkdir bin.v2/libs/math
common.mkdir bin.v2/libs/math/config
common.mkdir bin.v2/libs/math/config/gcc-mingw-4.4.4
common.mkdir bin.v2/libs/math/config/gcc-mingw-4.4.4/debug
common.mkdir bin.v2/libs/math/config/gcc-mingw-4.4.4/debug/target-os-windows
gcc.compile.c++ bin.v2/libs/math/config/gcc-mingw-4.4.4/debug/target-os-windows/has_gcc_visibility.o
cc1plus: warnings being treated as errors
libs/math/config/has_gcc_visibility.cpp: In function ‘int main()’:
libs/math/config/has_gcc_visibility.cpp:13: error: visibility attribute not supported in this configuration; ignored

    "i586-mingw32msvc-g++"  -ftemplate-depth-128 -O0 -fno-inline -Wall -g -Werror -fvisibility=hidden -DBOOST_ALL_NO_LIB=1  -I"." -c -o "bin.v2/libs/math/config/gcc-mingw-4.4.4/debug/target-os-windows/has_gcc_visibility.o" "libs/math/config/has_gcc_visibility.cpp"

...failed gcc.compile.c++ bin.v2/libs/math/config/gcc-mingw-4.4.4/debug/target-os-windows/has_gcc_visibility.o...
...failed updating 1 target...
...updated 5 targets...
    - ../config//has_gcc_visibility builds : no
...found 46 targets...
...updating 1 target...
gcc.compile.c++ bin.v2/libs/math/config/gcc-mingw-4.4.4/debug/target-os-windows/has_long_double_support.o
...updated 1 target...
    - ../config//has_long_double_support builds : yes
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
************************************************************
Trying to build Boost.Thread with pthread support.
If you need pthread you should specify the paths.
You can specify them in site-config.jam, user-config.jam
or in the environment.
For example:
PTW32_INCLUDE=C:\Program Files\ptw32\Pre-built2\include
PTW32_LIB=C:\Program Files\ptw32\Pre-built2\lib
************************************************************
/home/francis/orig/boost_1_46_1/tools/build/v2/build/virtual-target.jam:1079: in virtual-target.register-actual-name from module virtual-target
error: Duplicate name of actual target: <pstage/lib>libboost_date_time.a
error: previous virtual target { common%common.copy-libboost_date_time.a.STATIC_LIB { gcc%gcc.archive-libboost_date_time.a.STATIC_LIB { gcc%gcc.compile.c++-gregorian/greg_month.o.OBJ { gregorian/greg_month.cpp.CPP } } { gcc%gcc.compile.c++-gregorian/greg_weekday.o.OBJ { gregorian/greg_weekday.cpp.CPP } } { gcc%gcc.compile.c++-gregorian/date_generators.o.OBJ { gregorian/date_generators.cpp.CPP } } } }
error: created from ./stage-proper
error: another virtual target { common%common.copy-libboost_date_time.a.STATIC_LIB { gcc%gcc.archive-libboost_date_time.a.STATIC_LIB { gcc%gcc.compile.c++-gregorian/greg_month.o.OBJ { gregorian/greg_month.cpp.CPP } } { gcc%gcc.compile.c++-gregorian/greg_weekday.o.OBJ { gregorian/greg_weekday.cpp.CPP } } { gcc%gcc.compile.c++-gregorian/date_generators.o.OBJ { gregorian/date_generators.cpp.CPP } } } }
error: created from ./stage-proper
error: added properties: <debug-symbols>off <define>NDEBUG <inlining>full <optimization>speed <runtime-debugging>off <variant>release
error: removed properties: <debug-symbols>on <inlining>off <optimization>off <runtime-debugging>on <variant>debug
/home/francis/orig/boost_1_46_1/tools/build/v2/build/virtual-target.jam:490: in actualize-no-scanner from module object(file-target)@3884
/home/francis/orig/boost_1_46_1/tools/build/v2/build/virtual-target.jam:135: in object(file-target)@3884.actualize from module object(file-target)@3884
/home/francis/orig/boost_1_46_1/tools/build/v2/build-system.jam:748: in load from module build-system
/home/francis/orig/boost_1_46_1/tools/build/v2/kernel/modules.jam:283: in import from module modules
/home/francis/orig/boost_1_46_1/tools/build/v2/kernel/bootstrap.jam:142: in boost-build from module
/home/francis/orig/boost_1_46_1/boost-build.jam:17: in module scope from module

It says libicu is not found on my system, but according to Synaptic Package Manage I have the libicu-dev package installed.它说在我的系统上找不到 libicu,但根据 Synaptic Package Manage 我安装了libicu-dev包。

I'm not sure how to get it right.我不知道如何做对。 Can anyone help?任何人都可以帮忙吗?

Update 1更新 1

Following @Luke's recoommendation I now gcc-mingw toolset.按照@Luke 的建议,我现在使用gcc-mingw工具集。 So now my build instructions look like this:所以现在我的构建说明如下所示:

tar xvf boost_1_46_1.tar.gz
cd boost_1_46_1/
echo "using gcc : 4.4.4: i586-mingw32msvc-g++ ;" > user-config.jam
./bootstrap.sh
./bjam toolset=gcc-mingw target-os=windows

Which leads to the following errors:这会导致以下错误:

error: toolset gcc initialization:
error: version 'mingw' requested but 'g++-mingw' not found and version '4.4.5' of default 'g++' does not match
error: initialized from
/home/francis/orig/boost-mingw/boost_1_46_1/tools/build/v2/build/toolset.jam:38: in toolset.using from module toolset
/home/francis/orig/boost-mingw/boost_1_46_1/tools/build/v2/build-system.jam:481: in process-explicit-toolset-requests from module build-system
/home/francis/orig/boost-mingw/boost_1_46_1/tools/build/v2/build-system.jam:561: in load from module build-system
/home/francis/orig/boost-mingw/boost_1_46_1/tools/build/v2/kernel/modules.jam:283: in import from module modules
/home/francis/orig/boost-mingw/boost_1_46_1/tools/build/v2/kernel/bootstrap.jam:142: in boost-build from module
/home/francis/orig/boost-mingw/boost_1_46_1/boost-build.jam:17: in module scope from module

Update 2更新 2

I have also tried specifying gcc-mingw in the user-config.jam file.我还尝试在user-config.jam文件中指定gcc-mingw Then my build instructions look like this:然后我的构建说明如下所示:

tar xvf boost_1_46_1.tar.gz
cd boost_1_46_1/
echo "using gcc-mingw : 4.4.4: i586-mingw32msvc-g++ ;" > user-config.jam
./bootstrap.sh
./bjam toolset=gcc-mingw target-os=windows

Which leads to:这导致:

error: version 'mingw' requested but 'g++-mingw' not found and version '4.4.5' of default 'g++' does not match

Update 3更新 3

Specifying g++-mingw in the user-config.jam file:user-config.jam文件中指定g++-mingw

using g++-mingw : 4.4.4: i586-mingw32msvc-g++ ;

...leads to the same error. ...导致同样的错误。

I got similar error messages.我收到了类似的错误消息。 Eventually I was able to compile it using exactly the following commands:最终我能够完全使用以下命令编译它:

$ echo "using gcc : : i686-w64-mingw32-g++ ;" > user-config.jam
$ ./bootstrap.sh
$ ./b2 --user-config=user-config.jam toolset=gcc-mingw target-os=windows release

I believe your problem is that you don't specify the "--user-config=user-config.jam" parameter.我相信您的问题是您没有指定“--user-config=user-config.jam”参数。 The next problem I encountered was that there will be a name conflict unless I specify either debug or release build (--layout=tagged or --layout=versioned might work also).我遇到的下一个问题是,除非我指定 debug 或 release build(--layout=tagged 或 --layout=versioned 也可能有效),否则会出现名称冲突。

This is the commands I use.这是我使用的命令。 I have tested them for boost 1.46 and 1.49.我已经测试了它们的 boost 1.46 和 1.49。

To begin, create links to the compiler inside /usr/i686-w64-mingw32/bin.首先,在 /usr/i686-w64-mingw32/bin 中创建指向编译器的链接。 You can run this script :您可以运行此脚本:

#!/bin/bash

binDir="/usr/bin"
destDir="/usr/i686-w64-mingw32/bin"

cd "$binDir"
mkdir -p "$destDir"

for name in $(ls i686-w64-mingw32*); do
    newName=$(echo "$name" | sed -e "s/i686-w64-mingw32-\(.\?\)/\1/")
    if [ -f "$destDir/$newName" ]; then
        rm "$destDir/$newName"
    fi
    ln -s "$binDir/$name" "$destDir/$newName"
done

Then, install bjam.然后,安装 bjam。 On ubuntu / debian, it is included in the package "libboost1.48-dev"在 ubuntu / debian 上,它包含在包“libboost1.48-dev”中

apt-get install libboost1.48-dev

To finish, become root and run最后,成为 root 并运行

env PATH=/usr/i686-w64-mingw32/bin:$PATH bjam toolset=gcc target-os=windows variant=release threading=multi threadapi=win32 link=static --prefix=/usr/i686-w64-mingw32 -j 4 --without-mpi --without-python -sNO_BZIP2=1 -sNO_ZLIB=1 --layout=tagged install

Done !完毕 !

I had some difficulty with this too, but it seems to be working for me now.我也遇到了一些困难,但现在它似乎对我有用。 To be clear, I'm cross compiling on Linux for Windows.需要明确的是,我正在 Linux for Windows 上进行交叉编译。

in user-config.jam:在 user-config.jam 中:

using gcc : mingw32 : i686-w64-mingw32-g++ ;

Note that the second term "mingw32" is an arbitrary "version" tag.请注意,第二项“mingw32”是一个任意的“版本”标签。 The toolset flag combines the compiler name and the version name w/ a dash.工具集标志结合了编译器名称和带有破折号的版本名称。 So, in my case, gcc-mingw32.所以,就我而言,gcc-mingw32。 The third term is what actually gets invoked ("i686-w64-mingw32-g++").第三项是实际被调用的内容(“i686-w64-mingw32-g++”)。 Obviously your version of mingw's compiler may have a different name.显然,您的 mingw 编译器版本可能具有不同的名称。

Here is how I invoked bjam:这是我调用 bjam 的方式:

./b2 toolset=gcc-mingw32 target-os=windows threadapi=win32 --build-type=complete --prefix=/usr/x86_64-w64-mingw32/local --layout=tagged --without-python -sNO_BZIP2=1 -sNO_ZLIB=1

I got all the interesting flags from Congelli501's answer.我从 Congelli501 的回答中得到了所有有趣的标志。 But didn't bother with the directory of links approach.但并没有打扰链接方法的目录。

Cross-compiling boost 1.72.0 for Windows on Ubuntu 18.04Ubuntu 18.04上为 Windows 交叉编译boost 1.72.0


Install MinGW安装 MinGW

$ sudo apt install mingw-w64 mingw-w64-tools

$ sudo update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix
$ sudo update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix
$ sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
$ sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix

32-bit Compilation (install path: ./boost-x86 ) 32 位编译(安装路径: ./boost-x86 - ./boost-x86

$ echo "using gcc :  : i686-w64-mingw32-g++ ;" > user-config.jam
$ ./bootstrap.sh
$ ./b2 --user-config=./user-config.jam --prefix=./boost-x86 target-os=windows address-model=32 variant=release install

64-bit Compilation (install path: ./boost-x64 ) 64 位编译(安装路径: ./boost-x64 - ./boost-x64

$ echo "using gcc :  : x86_64-w64-mingw32-g++ ;" > user-config.jam
$ ./bootstrap.sh
$ ./b2 --user-config=./user-config.jam --prefix=./boost-x64 target-os=windows address-model=64 variant=release install

According to this it looks like you should be using the toolset=gcc-mingw .根据这个样子,你应该使用的toolset=gcc-mingw You have toolset=gcc .你有toolset=gcc

As Luke already mentioned, toolset=gcc-mingw will certainly help.正如 Luke 已经提到的, toolset=gcc-mingw肯定会有所帮助。

Your libicu-dev is 99% sure the linux library headers, which is not for mingw.您的libicu-dev 99% 确定 linux 库头文件,这不适用于 mingw。 You'll either have to build it yourself or get it from someplace (could be your distribution, otherwise you'll need to build it from source)您要么必须自己构建它,要么从某个地方获取它(可能是您的发行版,否则您需要从源代码构建它)

I had same problem.我有同样的问题。 Try specifying only a single build variant (ie, add "variant=Release link=shared runtime-link=shared")尝试仅指定一个构建变体(即添加“variant=Release link=shared runtime-link=shared”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM