---
# System prepended metadata

title: How to build OpenOCD using MinGW?

---

# How to build OpenOCD using MinGW?

## 1. build libftdi and libusb

libftdi source: `git clone git@github.com:lipro/libftdi.git`
libusb source: `git clone git@github.com:libusb/libusb.git`

* Build libusb.
```
# Create sysroot for MinGW build.
mkdir -p $HOME/mingw-sysroot

# Create mingw-pkg-config and export it.
export PKG_CONFIG=mingw-pkg-config

# Build libusb
${LIBUSB_SOURCE}/configure --build=`${LIBUSB_SOURCE}/config.guess` \
                           --host=i686-w64-mingw32 \
                           --prefix=/usr \
                           --with-sysroot=$HOME/mingw-sysroot/
make install DESTDIR=$HOME/mingw-sysroot
```

* Build libftdi.

Edit `cmake/Toolchain-i686-w64-mingw32.cmake`.
```
-SET(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32 )
+SET(CMAKE_FIND_ROOT_PATH $HOME/mingw-sysroot )
```

```
# Build libftdi
cmake -DCMAKE_TOOLCHAIN_FILE=${LIBFTDI_SOURCE}/cmake/Toolchain-i686-w64-mingw32.cmake \
      -DCMAKE_INSTALL_PREFIX="/usr" \
      -DPKG_CONFIG_EXECUTABLE=`which mingw-pkg-config`
make install DESTDIR=$HOME/mingw-sysroot
```

## 2. build OpenOCD with customized pkg-config

```
export PKG_CONFIG=mingw-pkg-config
${SOURCE}/configure --host=i686-w64-mingw32 \
                    --prefix=/usr \
                    --with-sysroot=$HOME/mingw-sysroot
make -j8
make install DESTDIR=$HOME/mingw-sysroot
```

## FAQ
* Can not find libgcc_s_sjlj-1.dll?
A: Copy from your build machine. For example, copy libgcc_s_sjlj-1.dll from /usr/lib/gcc/i686-w64-mingw32/5.3-win32/libgcc_s_sjlj-1.dll

* How to create mingw-pkg-config?
A: Refer to [Supporting Cross-Compilation](https://autotools.io/pkgconfig/cross-compiling.html?utm_source=www.flameeyes.eu&utm_medium=url&utm_campaign=vanitydomainssite)