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 http://gentoo-wiki.com/HOWTO_MinGW 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 has over 20 years of technology leadership experience in Software Testing / Development / Project Management and Team Leadership in multiple industry sectors, including: Telco, Healthcare, Technology and government. He is currently working as a Senior Test Consultant for Planit Software Testing. Master's Degree in Public Information Information Systems, and over 10 years of board governance experience for multiple organisations. Full bio is available at: http://www.linkedin.com/in/dingfelder Follow him on Twitter at http://twitter.com/dingfelder Andy Dingfelder 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.