- Linux mingw cross compilation
- Overview
- Installing the prerequisites for cross-compilation
- Setting up the build directory and getting the sources
- Making cross-compilation easy
- Compiling LZO
- Compiling Zlib
- Compiling LibreSSL
- Compiling tinc
- Cross-Compiling Under Linux
- Contents
- Building for i386 on an x86_64 machine
- Cross-compiling under Linux for MS Windows
- Example usage
- Contrib libraries
- Flags
- environment variables
- SDL’s Script
- Note about WINE
- Autoconf/Automake unit testing suites
- Testing the created executables
- MinGW кросс-компиляция на Linux
- Решение
- Другие решения
- mingw cross compilation from Linux to Windows #153
- Comments
- NeroBurner commented Jun 21, 2017
- ruslo commented Jun 21, 2017
- ruslo commented Jun 21, 2017
- NeroBurner commented Jun 21, 2017 •
- ruslo commented Jun 21, 2017
- NeroBurner commented Jun 22, 2017
- ruslo commented Jun 22, 2017
- NeroBurner commented Jun 22, 2017
- ruslo commented Jun 22, 2017
- ruslo commented Jan 7, 2018
Linux mingw cross compilation
This howto describes how to create a 64-bit Windows binary of tinc. Although it is possible to compile tinc under Windows itself, cross-compiling it under Linux is much faster. It is also much easier to get all the dependencies in a modern distribution. Therefore, this howto deals with cross-compiling tinc with MinGW under Linux on a Debian distribution.
Overview
The idea is simple:
- Install 64-bit MinGW.
- Create a directory where we will perform all cross-compilations.
- Get all the necessary sources.
- Cross-compile everything.
Installing the prerequisites for cross-compilation
There are only a few packages that need to be installed as root to get started:
Other Linux distributions may also have 64-bit MinGW packages, use their respective package management tools to install them. Debian installs the cross-compiler in /usr/x86_64-w64-mingw32/ . Other distributions might install it in another directory however. Check in which directory it is installed, and replace all occurences of x86_64-w64-mingw32 in this example with the correct name from your distribution.
Setting up the build directory and getting the sources
We will create a directory called mingw64/ in the home directory. We use apt-get and wget to get the required libraries necessary for tinc, and use git to get the latest development version of tinc.
Making cross-compilation easy
To make cross-compiling easy, we create a script called mingw64 that will set up the necessary environment variables so configure scripts and Makefiles will use the 64-bit MinGW version of GCC and binutils:
If $HOME/bin is not already part of your $PATH , you need to add it:
We use this script to call ./configure and make with the right environment variables, but only when the ./configure script doesn’t support cross-compilation itself. You can also run the export commands from the mingw64 script by hand instead of calling the mingw64 script for every ./configure or make command, or execute $HOME/bin/mingw64 $SHELL to get a shell with these environment variables set, but in this howto we will call it explicitly every time it is needed.
Compiling LZO
Cross-compiling LZO is easy:
If it fails with a message about not passing the “ACC” test, create a symlink for the missing getopt.h file as mentioned above.
Compiling Zlib
Cross-compiling Zlib is also easy, but a plain make failed to compile the tests, so we only build the static library here:
Compiling LibreSSL
Tinc can use either OpenSSL or LibreSSL. The latter is recommended.
Compiling tinc
Now that all the dependencies have been cross-compiled, we can cross-compile tinc. Since we use a clone of the git repository here, we need to run autoreconf first. If you want to cross-compile tinc from a released tarball, this is not necessary.
Источник
Cross-Compiling Under Linux
Contents
Building for i386 on an x86_64 machine
Reminder: If when compiling from source you decide you’d like to recompile with a different set of options, or stop the build in order to change some of the options you’ve selected, you must first run `make distclean` (`make clean` only removes object files) in order to remove generated configuration files before you run the configure script again with your new options. If you accidentally stop the build (by hitting ctrl-c or something) and do not wish to change any of the options, you can safely restart the build by simply typing the `make` command and it will continue right where it left off.
%debian if ./configure complains about not being able to find gtk-config, install the ‘libgtk2.0-dev’ package %%
If the compile fails with the error «had to relocate PCH», try adding «—disable-precomp-headers’ to your ./configure line.
You can create windows binaries without even booting to Windows! see Cross-Compiling Under Linux.
You may need to build 32-bit apps on an x86_64 Linux box (Suse or RHEL WS3 which is what I have). On my box at least, the 32-bit gtk libs aren’t installed, so I opted to build the plain X11 version, but the config below should work for either one.
Configure like this:
On RHEL WS 3, there are some missing lib symlinks in /usr/lib, e.g. no libX11.so (should be a symlink to libX11.so.X.Y). You’ll have to make those manually. They should be pretty obvious config or build failures.
Also, the configure script tries to search in /usr/lib64 and /usr/X11R6/lib64; remove those from SEARCH_LIBS near the top of the configure script (not doing this would make it try to link with e.g. -lXinerama, which exists but only in the 64 bit world.)
Cross-compiling under Linux for MS Windows
- Install The Mingw Cross-Compiler.
- Compile wxWidgets
- Download wxWidgets source
- Compile with ./configure —prefix=/usr/local/i586-mingw32 —host=i586-mingw32msvc —build=i686-linux —your_optional_switches
Host string differs depending on mingw installations, you should check your mingw cross compiler for the exact value. Build option can also be different if you’re not using Linux on x86, of course. For example, if you use mingw32 from Debian or Ubuntu packages under Linux on x86-64 architecture the command would be: ./configure —prefix=/usr/local/i586-mingw32msvc —host=i586-mingw32msvc —build=x86_64-linux —your_optional_switches
You may use ‘checkinstall make install’ instead of ‘make install’ in order to create a package and allow clean removal of the binaries.
- Embedding icons in your cross-compiled binary: Cross-Compiling Windows Resources
- Embedding other files: Embedding PNG Images
- Several tips, tricks and workarounds as well as Eclipse configuration: wxWindows application compile (for Linux) and cross-compile (for Windows) under Linux/Eclipse/CDT
- IBM DeveloperWorks article
- Cross compiling RLS AVON with MinGW on Linux (simple instructions for installing environment, compiling wxWidgets, and compiling an certain wxWidgets application)
Note: The SDL scripts and these directions cannot be mixed. Note: By disabling threads (with —disable-threads), you can avoid a dependency on the ming dll
Example usage
Once installed, save the following file as winhello.c (stolen from Installing and Using the MinGW Cross-Compiler on Mac OS X):
To build the example, execute the following command:
and run it, for example, with wine: wine winhello.exe
Contrib libraries
Couldn’t compile the contrib directory with the wxMSW 2.4.2 sources, use the latest cvs.
Flags
You might need these flags when compiling:
And these while linking:
environment variables
VZ: Note that this is unnecessary when using autoconf cross-compilation support.
In order to use the cross-compiler tools you need to replace the normal tools in makefiles. This is easier to do just exporting some environment variables before running configure/make:
SDL’s Script
See also: BuildCVS.txt in the tar of the SDL scripts
http://www.libsdl.org/extras/win32/cross/ contains scripts that automate the compiler build process described above.
Download build-cross.sh, cross-configure.sh, and cross-make.sh.
Run the script build-cross.sh.
Download the CVS version wxAll and uncompress it.
Copy cross-configure.sh and cross-make.sh to the wxWidgets-2.5.2 directory.
Run cross-configure.sh and cross-make.sh and you should be done. 🙂
From MXE page — «MXE (M cross environment) is a GNU Makefile that compiles a cross compiler and cross compiles many free libraries such as SDL and Qt.»
MXE can be used to cross-compile wxWidgets projects. You can install MXE according to the steps in the tutorial, go to the MXE directory and issue the following command:
Now, ensure that you have /usr/bin in the PATH and compile your project with the following command:
Note about WINE
Make sure to turn off binfmt support before running configure (Debian: /etc/init.d/binfmt-support stop), which invokes wine for .exe files; otherwise configure will think it does NOT use a cross-compiler.
Autoconf/Automake unit testing suites
(maybe this section should go somewhere else?)
It is possible to autotest your code using wine (you are using unit tests, right?). This makes it very easy to script code under Unix to build multiple platforms, then test, without intervention. This section focusses on testing console-able objects.
First familiarise yourself with building test binaries with autoconf and automake. I recommend cppunit (for C++ systems). There’s plentiful documentation on cppunit’s website on integrating cppunit with Makefile.am. One show-stopping step is the ability to test msw binaries in the same way (make check) one tests unix binaries.
To take advantage of wine (running your tests automatically with wine), first make sure that wine may run headless. If you have access to a graphical terminal then this isn’t important (if you’re Ok with having wine spout gobbledygock to a window with every run). Make sure your test-directory Makefile.am’s have all TESTS tokens suffixed with $(EXEEXT):
Next add a configure.ac (you have upgraded to using .ac instead of .in, right?) line manipulating the macro TESTS_ENVIRONMENT:
In this I assume that WINE has been set with AC_CHECK_PROGS or something (even `WINE = wine’). This will have all tests run in the following format:
Where dir is the path and tst is the test name (remember that EXEEXT). That’s it: wine will return the exit code of your running binary. You can also put a special shell or other token in there, but that exceeds the focus of this documentation. This assumed automake-1.9 and autoconf-2.57 but I’m fairly certain it works in earlier versions of both (uncertain about autoconf-2.13 style).
Testing the created executables
To test your mingw32 installation with a sample not using wxWidgets, look above («Example usage»).
To test your mingw32 installation with a real wxWidgets example, take minimal.cpp from the official examples. Fortunately, I didn’t have to fiddle around with the flags myself, I use wx-config for that — not the system-wide one, but the one compiled with the cross-Windows libraries below /usr/local/i586-mingw32!
Attention, there are are two caveats here that could cost you lots of time (it did cost me lots of time, hope I’ll save yours 😉
- When compiling, be sure to include the -c option. -o with an .o object file isn’t enough, mingw32 will try to link!
- When linking, be sure to include first your object files and then the libraries (given by wx-config). When compiling, the order isn’t too important, but if you exchange libraries and object files at the linking stage, you’ll get lots of undefined references. The reason is that a linker processes the libraries in order of their appearance (see documentation of «-l» at http://sourceware.org/binutils/docs/ld/Options.html).
Finally, when executing your program with wine, qemu (works great!) or even on a real Windows box, don’t forget that even if you linked everything statically, you’ll also need mingwm10.dll in addition to your executable. Put in in the same directory and execute the binary from there, and everything works. I found mingwm10.dll gzipped in /usr/share/doc/mingw32-runtime/
Источник
MinGW кросс-компиляция на Linux
У меня есть проект, который я хочу скомпилировать для Windows. У меня есть соответствующий make-файл, все работает с g ++. Я побежал apt-get install mingw32 , скачал пакет размером 100 мегабайт, но я не могу узнать, как его запустить. Здесь нет mingw32 Исполняемый файл, и я не могу найти какую-либо помощь в Интернете, так как я на самом деле скомпилировать его?
Решение
Если вы видите выход dpkg -L mingw32 вы можете видеть, что пакет содержит набор инструментов, то есть набор альтернативных инструментов (компилятор, компоновщик и т. д.), полезных для компиляции вашего кода в другой системе.
Вы должны использовать /usr/bin/i586-mingw32msvc-g++ для того, чтобы скомпилировать ваш код. Если я правильно помню, существует переменная, которая говорит Makefile использовать подобную цепочку инструментов.
Другие решения
Другой вариант — взглянуть на Mingw Cross Environment (MXE ), которая специально предназначена для кросс-компиляции из Linux в Windows (а в последнее время и в Mac). Пакет имеет встроенный xupport для большого количества библиотек и активно развивается. Просто взгляните на веб-сайт, чтобы узнать, подходит ли он вам.
Кстати, предлагается использовать разработку, а не выпускную версию. Это связано с тем, что версии выпуска, как правило, очень быстро устаревают из-за того, что сопровождающие (из библиотек) меняют URL-адреса, что приводит к повреждению версии выпуска MXE. Версия для разработки, как правило, более современная.
Я использовал это для кросс-компиляции postgres:
Другие проекты делают это по-другому, например, ffmpeg:
Источник
mingw cross compilation from Linux to Windows #153
Comments
NeroBurner commented Jun 21, 2017
as mentioned over at hunter ruslo/hunter#846
I don’t know where to put this file so I created this issue
contents of Toolchain-Ubuntu-mingw64.cmake
The text was updated successfully, but these errors were encountered:
ruslo commented Jun 21, 2017
Looks similar to:
I guess you can start with:
To create linux-mingw64 toolchain.
ruslo commented Jun 21, 2017
I think we don’t need this if you’re using Hunter. find_package should never return anything from system if Hunter used, see:
NeroBurner commented Jun 21, 2017 •
where should I set the windres variable needed for cross-compiling to windows
Edit:
and more importantly, where is the following variable set?
ruslo commented Jun 21, 2017
I think it will not hurt if we will add it to the compiler/gcc-cross-compile.cmake .
In top linux-mingw64 .
NeroBurner commented Jun 22, 2017
with this we could run mingw-w64 cross compiled tests with wine64 or armhf targets with qemu
ruslo commented Jun 22, 2017
should we add emulator support?
It will not hurt I guess. Is emulator a part of mingw-w64 package?
NeroBurner commented Jun 22, 2017
no, it would need an extra emulator installed. And for mingw that would be wine (to run windows binaries)
ruslo commented Jun 22, 2017
no, it would need an extra emulator installed
In this case we can add CMAKE_CROSSCOMPILING_EMULATOR variable but only if it will not return error if emulator not found.
ruslo commented Jan 7, 2018
Closing inactive discussion.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник