---
# System prepended metadata

title: How to do cross-compiling using MinGW?

---

# How to do cross-compiling using MinGW?

## 1. Prepare a pkg-config wrapper

  - Create sysroot for MinGW. For example, create a folder named $HOME/mingw-sysroot

  - Create ${CHOST}-pkg-config wrapper. The wrapper will set PKG_CONFIG_SYSROOT_DIR as sysroot.

```
#!/bin/sh

# Point to your sysroot.
SYSROOT=$HOME/mingw-sysroot

export PKG_CONFIG_DIR=
export PKG_CONFIG_LIBDIR=${SYSROOT}/usr/lib/pkgconfig:${SYSROOT}/usr/share/pkgconfig
export PKG_CONFIG_SYSROOT_DIR=${SYSROOT}

exec pkg-config "$@"
```

  - Export PKG_CONFIG as your wrapper.

```
export PKG_CONFIG=${CHOST}-pkg-config
```

## 2. Config with new sysroot.

```
./configure --host=i686-w64-mingw32 \
            --prefix=/usr \
            --with-sysroot=$HOME/mingw-sysroot
```

3. Make and install.

```
make install DESTDIR=$HOME/mingw-sysroot
```

Reference:
* [Supporting Cross-Compilation](https://autotools.io/pkgconfig/cross-compiling.html?utm_source=www.flameeyes.eu&utm_medium=url&utm_campaign=vanitydomainssite)
* [How to use MinGW to cross compile software for Windows](https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/cross_compiling/Mingw)