[ACCEPTED]-Undefined reference to GetStockObject@4-eclipse

Accepted answer
Score: 10

Check the documentation, and make sure you link to the 1 required libraries (-lgdi32).

Score: 4

Best guess: you need to link gdi32.lib.


Score: 1

If your Win32 application is a non trivial 16 GUI you will need these link directives 15 to bring in the right libraries:

-lgdi32 -luser32 -lkernel32 -lcomctl32 -lm -mwindows
  • lgdi32: graphics subsystem
  • luser32: user subsystem
  • lkernel32: kernel subsystem
  • lcomctl32: common control dll versions
  • lm: math libraries
  • mwindows: standalone GUI (console free) application

The above 14 directives tell the linker which libraries 13 to link; this is a different concept than 12 compiler header files which define the library 11 function prototypes (among other things). For 10 instance, declaring <math.h> does not automatically 9 link the math lib; you need -lm. Also, <wingdi.h> does 8 not automatically link the gdi32 lib; you 7 need -lgdi32.

At the command line you literally 6 specify -lgdi32 (along with others) after all your 5 file names. Otherwise, how you specify how 4 to link the various subsystem libraries 3 depends on the IDE you are using for the 2 specific build target you're working on. Check 1 your documentation for the IDE of choice.

More Related questions