Setting up MinGW for C/C++ Win32

Find Tips and tricks on how to better use the Zeus IDE. Feel free to post your own tips but please do not post bug reports, feature requests or questions here.
Post Reply
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Setting up MinGW for C/C++ Win32

Post by jussij »

It is assumed that installed the MinGW compiler as described here.

If you start Zeus, select the Templates panel from the navigator on the left, select the C/C++ Document Type
from the list at the top and double click on the Application (Windows) option.

That will create a simple Win32 application. Save that code to the c:\temp\winapp.cpp file.

If you compile this using the Compiler, Compile menu you'll most likely get this error message:

Code: Select all

winapp.cpp:(.text+0x75): undefined reference to `_imp__GetStockObject@4'
winapp.cpp:(.text+0x202): undefined reference to `_imp__SetBkMode@8'
winapp.cpp:(.text+0x249): undefined reference to `_imp__SetTextColor@8'
winapp.cpp:(.text+0x281): undefined reference to `_imp__TextOutA@20'
These errors indicate in linking the winapp.exe the linker could not resolve the missing Win32 functions listed.

These are stock standard Win32 functions and they live in the gdi32 and user32 windows libraries.

So what is needed is add these libraries to the command line using the -l option so that the linker can resolve these functions.

To do this just change the command line to be as follows:

Code: Select all

g++.exe -x c++ -Wall -std=c++11 "$fn" -lgdi32 -luser32 -o "$fdd$fb.exe"
Now, re-compiling will result in no errors and the winapp.exe file is created in the temp folder.

Running this executable will display the Hello Windows Win32 GUI application shown below.
hello_windows.png
hello_windows.png (2.04 KiB) Viewed 9010 times
Cheers Jussi
Post Reply