Cross development environment (developing programs for windows on linux)

(Notice) This is a memo when I prepared an environment where I could also develop a windows application when I was developing a GUI program using wxWidget on ubuntu. This article was written on Google Sites a long time ago, and although the content is obsolete, I can't stand it disappearing, so I reprinted it. It has not been re-verified at the time of reprint (2020/8).

Installation of compiler and execution environment

1) Install gcc cross-compiler package

First, install a compiler (cross-compiler) that creates programs for windows on linux.

Packages to install

python


$ sudo apt-get install mingw-w64 binutils-mingw-w64 gcc-mingw-w64 g++-mingw-w64

Executable files (programs) created with gcc-mingw (generally) do not work on their own. You need two files, the compiled executable file and the mingw runtime library. Normal Windows users do not have the mingw runtime library, so you need to distribute the compiled program and the mingw library together.

The mingw library is included in the mingw32-runtime-package, so copy it to your current directory so you can distribute it with it.

runtime


$ cp /usr/share/doc/mingw32-runtime/mingwm10.dll.gz .
$ gunzip mingw10.dll

2) Create a test environment for windows programs in a linux environment

To run a program for windows on linux, you need a program to act for windows

install_wine


$ sudo apt-get install wine

3) Test with sample program

hello.cpp


#include <iostream>
int main(int ac,char*av[]){
    std::cout<<"hello"<<std::endl;
    return 0;
}

test


$  i686-w64-mingw32-g++ -static-libgcc -static-libstdc++  hello.cpp 

4) Set environment variables

setenv4cross.sh


export CC=i686-w64-mingw32-gcc
export CXX=i686-w64-mingw32-c++
export LD=i686-w64-mingw32-ld
export AR=i686-w64-mingw32-ar
export AS=i686-w64-mingw32-as
export NM=i686-w64-mingw32-nm
export STRIP=i686-w64-mingw32-strip
export RANLIB=i686-w64-mingw32-ranlib
export DLLTOOL=i686-w64-mingw32-dlltool
export OBJDUMP=i686-w64-mingw32-objdump
export RESCOMP=i686-w64-mingw32-windres
export WINDRES=i686-w64-mingw32-windres

set


$ source setenv4cross.sh

Install headers and libraries for multithreading

pthread (You may not need to install pthread separately now)

http://sourceforge.net/projects/mingw/files/MinGW/Base/pthreads-w32/pthreads-w32-2.9.1/

From

install_pthread


$ export SANDBOX=~/src/cross
$ mkdir pthread
$ tar xvf pthreads-w32-2.9.0-mingw32-pre-20110507-2-src.tar.lzma --lzma

# $ pkgbuild -e prep
# $ pkgbuild -e patch
# $ pkgbuild -e configure

$ cd pthreads

$ make CROSS=i686-w64-mingw32- clean GC-inlined -f GNUmakefile

$ mkdir -p $SANDBOX/{include,lib,bin}
$ cp libpthreadGC2.a $SANDBOX/lib/
$ cp *.h $SANDBOX/include/
$ cp pthreadGC2.dll $SANDBOX/bin/

Create wxWidgets for cross-compilation (if you like)

Compile and install Disable-shared etc. is up to you.

install wxWidgets


$ tar xjf wxWidgets-2.8.12.tar.bz
$ cd wxWidget-2.8.12
$ ./configure --prefix=/usr/local/i586-mingw32 --host=i586-mingw32msvc --enable-unicode --build=`./config.guess` --disable-shared
$ make
$ sudo make install

Test sample Don't forget to make a link to the runtime library.

$ cd samples
$ cd (What you want to try)
$ make
$ ln -s $SANDBOX/mingw10.dll .
(Execution)
$ make clean

How to compile source with wxWidgets

Basically, you can use wx-config installed for cross compile.

MINGW_PREFIX=i586-mingw32msvc
CXX=$(MINGW_PREFIX)-g++
LD=$(MINGW_PREFIX)-ld
WXCONFIG=/usr/local/i586-mingw32/bin/wx-config
WXCPPFLAGS=`$(WXCONFIG) --cppflags`
WXLIBS=`$(WXCONFIG) --libs`
t.exe: t.cpp
    $(CXX) $(WXCPPFLAGS) $(CPPFLAGS) -o t.exe t.cpp $(WXLIBS)

References

Search keywords: ubuntu, mingw, wine, cross complier, setup

Recommended Posts

Cross development environment (developing programs for windows on linux)
Django environment development on Windows 10
Create a Linux environment on Windows 10
Install Python development environment on Windows 10
pykintone on Windows Subsystem for Linux
Building an environment for "Tello_Video" on Windows
Build a Kubernetes environment for development on Ubuntu
Build a mruby development environment for ESP32 (Linux)
Create a Python virtual development environment on Windows
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Build a local development environment for Laravel6.X on Mac
Create a comfortable Python 3 (Anaconda) development environment on windows
Build a GVim-based Python development environment on Windows 10 (1) Installation
Create an environment for MkDocs on Amazon Linux (attempted)
Development environment suitable for ArcPy
Python + Kivy development on Windows
Prepare Chainer environment on Windows
F2py on Miniconda for Windows
Build Python environment on Windows
Linux on Windows -1-: debian introduction
[For organizing] Python development environment
[Tensorflow] Tensorflow environment construction on Windows 10
Linux environment construction (on WSL environment)
Use Linux on Windows 10 (WSL2)
Linux beginners create Ubuntu 16.04 environment on Docker (for Mac)-first half-
Build a GVim-based Python development environment on Windows 10 (2) Basic settings
Memo of Linux environment construction using VirtualBox + Vagrant on Windows 10
[Linux] [Initial Settings] Table of Contents for Development Environment Setup
How to set up WSL2 on Windows 10 and create a study environment for Linux commands
Create a Python environment for professionals in VS Code on Windows
Python environment construction memo on Windows 10
Example of building python development environment on windows (wsl2, vscode, pipenv)
Prepare Python development environment on Ubuntu
Anaconda python environment construction on Windows 10
(Windows10) Install Linux environment and gnuplot.
Install python2.7 on windows 32bit environment
WSL2 ~ Linux on Windows ~ (Part 1: Introduction)
[For beginners] Django -Development environment construction-
[Python3] Development environment construction << Windows edition >>
Python development environment options for May 2020
Python development environment construction on macOS
Emacs settings for Python development environment
[Linux] Docker environment construction on Redhat
Introduce Python 3.5.2 environment on Amazon Linux
[Definitive Edition] Building an environment for learning "machine learning" using Python on Windows
Procedure for building a kube environment on amazon linux2 (aws) ~ (with bonus)
Create a Python development environment on Windows (Visual Studio Code remote WSL).
Put MeCab binding for Python with pip on Windows, mac and Linux
Build Linux on a Windows environment. Steps to install Laradock and migrate
Notes for using OpenCV on Windows10 Python 3.8.3.
[UE4] Build DedicatedServer on Windows and Linux
Windows Subsystem for Linux is not displayed
Addition of local development environment on MacOS
Python development environment for macOS using venv 2016
Python 2.7, 3.4, 3.5 extension module build environment on Windows
Python project environment construction procedure (for windows)
Install wsl2 and master linux on windows
Windows → linux Tips for bringing in data
WSL2 (Windows Subsystem for Linux) installation procedure
Build an LNPP environment on Amazon Linux 2
Creating a python virtual environment on Windows