compiling windows apps on linux

now that we successfully used cmake to compile a linux app (in the last article), we will now try and compile it for windows.

I am doing this on Gentoo linux, so your mileage may vary if you used a different distribution.

I am starting with as a rough guide.

  • # emerge -va sys-devel/crossdev
  • # echo ‘PORTDIR_OVERLAY=”/usr/i686-mingw32/usr/portage /usr/local/portage $PORTDIR_OVERLAY”‘ >> /etc/make.conf
  • create the directory /usr/i686-mingw32/usr/portage
  • install the toolchain: # crossdev i686-mingw32

With Ubuntu/Debian you can simply install it using apt: “apt-get install mingw32”. This will install the toolchain as i586-mingw32msvc-gcc to /usr/bin/ .emerge the packages you want to have as cross compiled programs or libraries.

Once you have installed ming32, it is easy to compile for linux:

#  i686-mingw32-gcc helloworld.cpp -o wintest.exe

Now the next step in the puxxle is to get cmake to compile for both OSes  each time make is run.

About andy dingfelder

Andy is a CISO/CTO in the fintech sector with over 20 years of experience in Software Delivery and Team Leadership in multiple industry domains. Master's Degree (MPA) in Public Administration Information Systems and over 10 years of board governance experience for multiple organisations. Full bio is available at: and links available at or follow him on Twitter at Andy lives in the Wellington region, New Zealand with his wife and two daughters.
This entry was posted in C++, CDT, cmake, gentoo, linux, windows. Bookmark the permalink.