Reputation: 1811
I've created a program in Eclipse / MinGW / C (project type: C) which should just present an empty window. It also has the folowing line:
wndclassex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
The call to GetStockObject()
produces a compiler error:
Z:/mtsts_workspace/MTSTS/Debug/../WinMain.c:29: undefined reference to `GetStockObject@4'
Has anyone an idea what's wrong ?
Upvotes: 4
Views: 12463
Reputation: 79
If your Win32 application is a non trivial GUI you will need these link directives to bring in the right libraries:
-lgdi32 -luser32 -lkernel32 -lcomctl32 -lm -mwindows
lgdi32
: graphics subsystemluser32
: user subsystemlkernel32
: kernel subsystemlcomctl32
: common control dll versionslm
: math librariesmwindows
: standalone GUI (console free) applicationThe above directives tell the linker which libraries to link; this is a different concept than compiler header files which define the library function prototypes (among other things). For instance, declaring <math.h>
does not automatically link the math lib; you need -lm
. Also, <wingdi.h>
does not automatically link the gdi32 lib; you need -lgdi32
.
At the command line you literally specify -lgdi32
(along with others) after all your file names. Otherwise, how you specify how to link the various subsystem libraries depends on the IDE you are using for the specific build target you're working on. Check your documentation for the IDE of choice.
Upvotes: 0
Reputation: 400039
Check the documentation, and make sure you link to the required libraries (-lgdi32
).
Upvotes: 13