github:https://github.com/mxe/mxe
Introduction简介
MXE (M cross environment) is a GNU Makefile that compiles a cross compiler and cross compiles many free libraries such as SDL and Qt. Thus, it provides a nice cross compiling environment for various target platforms, which
MXE是一个GNU Makefile文件,它可以编译跨平台的编译器,跨编译许多免费类库,例如SDL和Qt。从而,它提供了一种跨平台的解决方案
- is designed to run on any Unix system可以运行在任何Unix系统
- is easy to adapt and to extend容易调节和扩展
- builds many free libraries in addition to the cross compiler除了可以编译跨平台的编译器以外,还编译了很多免费的类库
- can also build just a subset of the packages, and automatically builds their dependencies也可以只编译一个子集,从而自动编译它们的依赖
- downloads all needed packages and verifies them by their checksums
- is able to update the version numbers of all packages automatically
- directly uses source packages, thus ensuring the whole build mechanism is transparent
- allows inter-package and intra-package parallel builds whenever possible
- bundles ccache to speed up repeated builds
- integrates well with autotools, cmake, qmake, and hand-written makefiles
- has been in continuous development since 2007 and is used by several projects
- has pre-compiled binaries that can be used in Continuous Integration systems
Supported Toolchains
Compiler and runtime: MinGW-w64.
Target OS Packages
Static Shared
32 bit Windows 99% (379/381) 72% (273/381)
64 bit Windows 94% (360/381) 71% (271/381)
These numbers were last updated on December 16, 2015. See the current status for individual packages.
Executables built for 32 bit Windows can be executed on 64 bit Windows as well.
How to choose MXE target:
If you want a 64 bit Windows executable, statically linked into one big executable: use MXE_TARGETS x86_64-w64-mingw32.static;
If you want a 64 bit Windows executable, split into an executable and dependant dlls use MXE_TARGETS x86_64-w64-mingw32.shared;
If you want a 32 bit Windows executable, statically linked into one big executable: use MXE_TARGETS i686-w64-mingw32.static;
If you want a 32 bit Windows executable, split into an executable and dependant dlls use MXE_TARGETS i686-w64-mingw32.shared.
Remark: The 'w64-mingw32' in those names are left-overs from historical evolutions in the open source cross-compilation world and refer in no way to the result being 64 or 32 bit Windows.
OpenMP (libgomp) and pthreads (winpthreads) are always available.
When building shared libraries, there are several approaches to recursively finding DLL dependencies (alphabetical list):
go script
pe-util packaged with mxe
python script
shell script
Experimental support for GCC with posix threads was added in November 2015. Since January 2019 it is used by default.
Experimental support for alternate GCC Exception Handling was added in February 2017.
Screenshots
在当今的世界,C++程序员是不能绕过Windows的,但是很多类库都是Linux平台下的,那么如何才能完美的移植到Windows平台或者其它平台呢?跨平台编译是一件让人头疼的事,因为很多依赖库,各个平台并不相同,这里面包括版本,等等。MXE就是让你能在Linux下编译出Windows应用程序。应该不仅仅是在Windows程序中运行Linux程序,模拟出Windows的效果。
>>Linux下编译静态MinGW环境,编译windows平台Qt程序(使用MXE):https://www.cnblogs.com/findumars/p/6251014.html
Step 1: Requirements and Download
First, you should ensure that your system meets MXE'srequirements. You will almost certainly have to install some stuff.
When everything is fine, download the current version:
git clone https://github.com/mxe/mxe.git
If you don't mind installing it in your home directory, just skip the following step and go straight to step 3.
MXE builds and installs everything under the same top-level directory and is not relocatable after the first packages are built.
Due to limitations of GNU Make, the path of MXE is not allowed to contain any whitespace characters.
Step 2: System-wide Installation (optional)
Now you should save any previous installation of the MXE. Assuming you've installed it under /opt/mxe (any other directory will do as well), you should execute the following commands:
su
mv /opt/mxe /opt/mxe.old
exit
Then you need to transfer the entire directory to its definitive location. We will assume again you use /opt/mxe, but feel free to use any other directory if you like.
su
mv mxe /opt/mxe
exit
We're almost done. Just change to your newly created directory and get going:
cd /opt/mxe
Step 3a: Build MXE
Enter the directory where you've downloaded MXE. Now it depends on what you actually want – or need.
If you choose to enter:
make
you're in for a long wait, because it compiles a lot of packages. On the other hand it doesn't require any intervention, so you're free to do whatever you like – like watch a movie or go for a night on the town. When it's done you'll find that you've installed a very capable Win32 cross compiler onto your system.
If you only need the most basic tools you can also use:
make cc
and add any additional packages you need later on. You can also supply a host of packages on the command line, e.g.:
make gtk lua libidn
Targets can also be specified on the command line. By default, only i686-w64-mingw32.static is built, but you can build your toolchain(s) of choice with:
make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static'
or by adjusting the MXE_TARGETS
variable in settings.mk
.
You'll always end up with a consistent cross compiling environment.
If you have trouble here, please feel free to contact the mxe team through the issue tracker or mailing list.
After you're done it just needs a little post-installation.
Step 3b: Install MXE from the binary distribution
Instead of building MXE packages from source, you can download precompiled packages. There are two options: tar archives and Debian packages. See pkg.mxe.cc.
Step 4: Environment Variables
Edit the appropriate config script (.bashrc, .cshrc, .profile, .zshrc, etc.) for your shell in order to change $PATH:
export PATH=/where MXE is installed/usr/bin:$PATH
You may be tempted to also add $(TARGET)/bin
to your path. You never want to do this, the executables and scripts in there will cause conflicts with your native toolchain.
In case you are using custom $PKG_CONFIG_PATH entries, you can add separate entries for cross builds:
export PKG_CONFIG_PATH="entries for native builds"
export PKG_CONFIG_PATH_i686_w64_mingw32_static="entries for MXE builds"
Remember to use i686-w64-mingw32.static-pkg-config instead of pkg-config for cross builds. The Autotools do that automatically for you.
Note that any other compiler related environment variables (like $CC, $LDFLAGS, etc.) may spoil your compiling pleasure, so be sure to delete or disable those.
For the most isolated and repeatable environment, use a white-list approach:
unset `env | \
grep -vi '^EDITOR=\|^HOME=\|^LANG=\|MXE\|^PATH=' | \
grep -vi 'PKG_CONFIG\|PROXY\|^PS1=\|^TERM=' | \
cut -d '=' -f1 | tr '\n' ' '`
Congratulations! You're ready to cross compile anything you like.
Step 5a: Cross compile your Project (Autotools)
If you use the Autotools, all you have to do is:
./configure --host=i686-w64-mingw32.static
make
If you build a library, you might also want to enforce a static build:
./configure --host=i686-w64-mingw32.static --enable-static --disable-shared
make
Don't worry about a warning like this:
configure: WARNING: If you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be used.
Everything will be just fine.
Step 5b: Cross compile your Project (CMake)
If you have a CMake project, you can use the provided cmake wrapper:
i686-w64-mingw32.static-cmake ...
This will automatically use the MXE version of cmake and locate the toolchain file.
Step 5c: Cross compile your Project (Qt)
If you have a Qt application, all you have to do is:
/<where-MXE-is-installed>/usr/i686-w64-mingw32.static/qt5/bin/qmake
make
Note that Qt 5 is in the "qt5" subdirectory. Qt 4 is in the "qt" subdirectory and its qmake can be invoked similarly.
If you are using Qt plugins such as the svg or ico image handlers, you should also have a look at the Qt documentation about static plugins.
Qt 4 only: Sql drivers (-qt-sql-*) and image handlers for jpeg, tiff, gif and mng are built-in, not plugins.
Step 5d: Cross compile your Project (Makefile)
If you have a handwritten Makefile, you probably will have to make a few adjustments to it:
CC=$(CROSS)gcc
LD=$(CROSS)ld
AR=$(CROSS)ar
PKG_CONFIG=$(CROSS)pkg-config
You may have to add a few others, depending on your project.
Then, all you have to do is:
make CROSS=i686-w64-mingw32.static-
That's it!
Step 5e: Cross compile your Project (OSG)
Using static OpenSceneGraph libraries requires a few changes to your source. The graphics subsystem and all plugins required by your application must be referenced explicitly. Use a code block like the following:
#ifdef OSG_LIBRARY_STATIC
USE_GRAPHICSWINDOW()
USE_OSGPLUGIN(<plugin1>)
USE_OSGPLUGIN(<plugin2>)
...
#endif
Look at examples/osgstaticviewer/osgstaticviewer.cpp
in the OpenSceneGraph source distribution for an example. This example can be compiled with the following command:
i686-w64-mingw32.static-g++ \
-o osgstaticviewer.exe examples/osgstaticviewer/osgstaticviewer.cpp \
`i686-w64-mingw32.static-pkg-config --cflags openscenegraph-osgViewer openscenegraph-osgPlugins` \
`i686-w64-mingw32.static-pkg-config --libs openscenegraph-osgViewer openscenegraph-osgPlugins`
The i686-w64-mingw32.static-pkg-config
command from MXE will automatically add -DOSG_LIBRARY_STATIC
to your compiler flags.
Further Steps
If you need further assistance, feel free to join the mailing listwhere you'll get in touch with the MXE developers and other users.
Download
>>CMake:https://www.gnu.org/software/make/manual/make.html
https://github.com/richelbilderbeek/mxe_tutorial https://wiki.openttd.org/Cross-compiling_for_Windows
MXE项目主页 交叉编译OpenTTD for Windows的首选方法是使用MXE。它是不灵活的,例如,你将被限制在某些版本的库中,但它节省了很多麻烦。 MXE是一组脚本。它将下载交叉编译器的源代码并为您的平台构建它。然后它将下载您选择的库的源代码,并使用它自己构建的交叉编译器为您编译它。一切都是自动化的(除了构建OpenTTD本身)。
[编译MXE]
首先,您可能需要在系统中安装一些软件包。请参阅MXE网站上的“要求”部分。在64位Ubuntu 14.10上,您需要:
autoconf automake autopoint bash bison bzip2 flex gettext git g++ gperf intltool libffi-dev libgdk-pixbuf2.0-dev libtool libltdl-dev libssl-dev libxml-parser-perl make openssl p7zip-full patch perl pkg-config python ruby scons sed unzip wget xz-utils g++-multilib libc6-dev-i386 libtool-bin
从git存储库下载MXE程序。我们将把MXE保存在/usr/local/MXE下。编译编译器和库。也可参阅MXE教程。
cd /usr/local
sudo git clone http://github.com/mxe/mxe.git
cd mxe
sudo make -j`nproc` gcc zlib libpng lzo freetype xz icu4c
默认情况下,创建一个可为32位Windows编译的软件。您也可以通过调整MXE_TARGETS选项来创建64位Windows套件,例如,要同时创建32位(i686-w64-mingw32.static)和64位(x86_64-w64-mingw32.static),请使用:
sudo make-j`nproc`MXE_TARGETS='i686-w64-mingw32.static x86_64-w64-mingw32.static'gcc zlib libpng lzo freetype xz icu4c
理论上MXE应该编译所有库而没有问题。但是,如果您遇到任何问题,您可以尝试调整一些问题。请参阅“故障排除”部分。
安装MXE
将/usr/local/mxe/usr/bin添加到$PATH变量。有关说明,请参阅“手动安装交叉编译器”。