compiling windows c/c++ on kali

mingw is a windows c/c++ compiler you can run under wine

it can be amazingly useful and convenient, but it has limitations; i’ll be installing visual studio on a windows vm at some point as well for those tricky cases

# install mingw
wget http://downloads.sourceforge.net/project/mingw/Installer/mingw-get-setup.exe
wine mingw-get-setup.exe
(select mingw base and c++, menu -> apply changes, quit)
wine regedit
(HKCU/Environment add string PATH c:\windows;c:\windows\system;c:\MinGW\bin)
rm mingw-get-setup.exe

# install some libs mingw needs
wget http://gojhonny.com/misc/mingw_bin.zip
unzip mingw_bin.zip -d /root/.wine/drive_c/windows/
rm mingw_bin.zip

# running
wine mingw32-gcc.exe foo.c -o foo.exe -lws2_32
wine mingw32-g++.exe foo.cpp -o foo.exe -lws2_32

# notes
– mingw can’t compile any .cpp with the ‘stdaxf’ include, which is a visual studio generated file that most often isn’t packaged with the source
– mingw can’t compile any .cpp with __asm sections, these sections must be translated into something it can cope with
– mingw can’t compile any .cpp with __try, __catch, __exception (MS extensions)

# some compile errors and fixes i’ve come across
– warning: incompatible implicit declaration of built-in function ‘printf’
add #include <stdio.h>
– warning: implicit declaration of function ‘read’
add #include <unistd.h>
– warning: implicit declaration of function ‘_kbhit’
add #include <conio.h>
– warning: implicit declaration of function ‘getch’
add #include <conio.h>
– warning: implicit declaration of function ‘toupper’
add #include <ctype.h>

Leave a Reply

Your email address will not be published. Required fields are marked *