[Linker error] undefined reference to `GetStockObject@4'

This is a discussion on [Linker error] undefined reference to `GetStockObject@4' within the Windows Programming forums, part of the Platform Specific Boards category; This is a problem compiling a windows program with DevCPP. I have included <wingdi.h> which declares GetStockObject, and it says ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    70

    [Linker error] undefined reference to `GetStockObject@4'

    This is a problem compiling a windows program with DevCPP. I have included <wingdi.h> which declares GetStockObject, and it says nothing about the file beeing missing... Is it something with @4?

  2. #2
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Did you create a Windows Project, instead of a Console one?

    Your error has to do with linking, it can find the prototype in your header files (.h), but it can't find the definition in your library files (.a).

    So re-create your project as a Windows one, or add this to your linker options. (I suggest the former).

    Code:
    -lgdi32

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Unless you have very specific requirements, I would include windows.h rather then the individual lower level headers.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    70
    The windows.h that comes with devcpp doesn't define GetStockObject but wingdi.h does. I thought the headers would also tell were the actual functions were located ie, gdi32.dll... But i'll do as you said..Thanks

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    70
    Now it's the DirectX func Direct3DCreate9 that won't work, obviously because calls are made to some DX dlls that my app don't mention, but were should I mention them?

  6. #6
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Now it's the DirectX func Direct3DCreate9 that won't work, obviously because calls are made to some DX dlls that my app don't mention, but were should I mention them?
    Good luck getting DirectX to work with Dev-C++. I have heard of legendary heroes managing this feat, but only after hours of tweaking and configuring Dev-C++.

    Getting DirectX 8.1 to Work with Dev-C++

    Edit:

    Could be useful. Or maybe not: DirectX 9.0 devpak
    Last edited by Dante Shamest; 03-29-2005 at 01:34 PM.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    70
    Hrm.. I just thought it was a matter of specifiyng what libs and functions in those libs which would all follow the ANSI C and windows standards.. but I guess microsoft don't want directx to work with rival compilers, allthough they do provide that free compiler ripped out from previous visual studio release that's posted Sticky here...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21