I'm working on an application written in C that's supposed to run on at least Linux and Windows. I usually work on Linux, so I'd like to be able to cross-compile my application for Windows.

My current setup:

  • Debian GNU/Linux amd64
  • No complex build system, just a simple Makefile
  • Using GCC for Linux, MinGW for Windows

My application depends on a number of libraries. Luckily, my distribution offers development headers, so compiling for Linux works pretty much out of the box using pkg-config to determine CFLAGS and LDFLAGS.

It doesn't work that well for Windows. My distribution provides a compiler toolchain for x86_64-w64-mingw32, which is able to find the development headers, but for some libraries I need different versions for Windows. Unfortunately, these versions are not provided by my distribution so I have to install them on my own.

So: Where do I install the development headers for Windows? How do I make pkg-config find it? Is there a way to just compile for Windows using a single command, just like I can compile for Linux by calling make?

In my case, one of the libraries in question is SDL2. Trying to compile with the headers shipped by my distribution produces a fatal error: iconv.h: No such file or directory. Googling for this error also tells us to use the Windows version. Other libraries seem to work during the compiling stage, but obviously it can't find them during the linking stage.

  • This may help: mingw.org/wiki/IncludePathHOWTO, specifically the section Using Headers Provided with Locally Installed External Libraries. Also, depending on the external library, you may very well have to obtain header files that were designed specifically for Windows. Dec 8, 2015 at 18:33

1 Answer 1


You should build any library you want to use with the x86_64-w64-mingw32 toolchain using the /usr/x86_64-w64-mingw32 prefix; typically:

./configure --prefix=/usr/x86_64-w64-mingw32 --host=x86_64-w64-mingw32

with any other options you need.

This will ensure that headers end up in /usr/x86_64-w64-mingw32/include, libraries in /usr/x86_64-w64-mingw32/lib, and pkg-config files in /usr/x86_64-w64-mingw32/lib/pkgconfig, which is where the toolchain expects to find them.

Regarding pkg-config, you should check that your ./configure calls use x86_64-w64-mingw32-pkg-config (which should happen automatically with the --host option). You’ll need to install mingw-w64-tools if you haven’t done so already.

(I’m the mingw-w64 maintainer in Debian. I would be interested in any feedback you have — in particular, I’ve been thinking of packaging Windows iconv for a while, and if that would have saved you time I’ll push that higher up my todo list.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .