Thread: Dev C++ linker error: undefined reference

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    17

    Unhappy Dev C++ linker error: undefined reference

    This is the first time Ive done any programming since a few classes 6 years ago, so the answer is likely to be pretty basic.

    I am compliling a Text editor in Dev C++ and getting the following error:

    [Linker error] undefined reference to `SetLayeredWindowAttributes@16'

    I have found that SetLayeredAttributes resides in user32.lib and the windows.h header file.

    I believe SetLayeredWindowAttributes@16 is comming from user32.def file. This is the only file on my computer that include the whole string. (It shows up a number of times minus the @16)

    The linker has the following switches:

    -lkernel32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lcomctl32 -lShlwapi -lopengl32 -lglu32 -luser32
    ../../lib/libuser32.a (<-- I added this one hopping to force recognition)

    No where in my code do I directly access this method, not certain which one of the includes is calling it.

    I dont have a clue what to try from here. Any help would be greatly appreciated.

    -Josh D.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Perhaps because its called something else?

    From MSDN
    BOOL SetLayeredWindowAttributes(
    HWND hwnd,
    COLORREF crKey,
    BYTE bAlpha,
    DWORD dwFlags
    );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    I don't know exactly these things (Dev-Cpp, etc.) get put together, but here's what I found:

    With my Cygwin gnu installation (gcc 3.3.1) on my WinXP box I found that the function was there (using nm libuser32.a in the lib\w32api directory. (Found an entry _SetLayeredWindowAttributes@16 under ds00487.o)

    I downloaded and installed Dev-Cpp, navigated to its lib directory, found libuser32.a, but, alas nm libuser32.a did not find the function. Just for kicks I looked in all of the .a files, and did not find an entry for _SetLayeredWindowAttributes or anything similar.

    So, I know this doesn't solve your problem, but maybe someone here can take it farther.

    Dave

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    17

    Salems suggestion still didnt work

    I didnt like the solution, because it will mask any future changes to this system include, but at I needed to try something.

    I copied

    BOOL SetLayeredWindowAttributes(
    HWND hwnd,
    COLORREF crKey,
    BYTE bAlpha,
    DWORD dwFlags
    );

    into one of my header files.

    I no longer get the previous problem. Now I get

    93 C:\Dev-Cpp\Projects\NoteXPad\glLogoControl.cpp
    invalid conversion from `DWORD (*)(void*)' to `DWORD (*)(void*)'

    Huh? Its complaining because of an invalid conversion from type A to type A? What am I missing here?

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    17

    Wink sorry, should include some info

    You probably cant help much without info on the line in question...

    Code:
    glData->hThread = CreateThread(NULL, 0, glLogoDrawThread, glData, 0, &glData->dwThread); // create the rendering thread
    where

    struct gldata_t *glData = (struct gldata_t *)LocalAlloc(LPTR, sizeof(struct gldata_t));

    Thanks for whatever help anyone can render.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    undefined reference to `SetLayeredWindowAttributes@16'
    These type of errors are common and have a common solution: check the header where the function is declared and meet any preprocessor condition that is required. In this case, SetLayeredWindowAttributes is declared in winuser.h and requires that you #define _WIN32_WINNT 0x0500 ( or #define _WIN32_WINNT _NT5 for recent winapi versions of mingw) prior to #include <windows.h>.
    invalid conversion from `DWORD (*)(void*)' to `DWORD (*)(void*)'
    Don't have a clue. Here's an example of the use of CreateThread with accompanying ThreadProc, comparison with which may give you some ideas about why your compiler is generating that error.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    17

    Talking Thanks Ken

    Thanks Ken,
    That was indeed the solution.

    Thanks also for the link to CreateThread information. I dont have a solution yet, but this is my first time working with threads, so thats not surprising.

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    17

    Question

    Hold the phone. This is just getting more and more bizzarre.

    I narrowed the offending parameter to glLogoDrawThread through trial and error. I passed zero for this and it worked, only now the initial problem is back. So the "fix" only postponed the initial error.

    Just to see if I could get something more informative out of the error message for the second issue, I tried changing glLogoDrawThread to both *glLogoDrawThread and &glLogoDrawThread. Neither of these changed the error message at all.
    Does that make any kind of sense?

    I wonder if McDonalds is hiring any fry cooks?

  9. #9
    Registered User
    Join Date
    Mar 2004
    Posts
    17
    One last piece of probably useless information.
    I can explicitly typecast it by:
    (DWORD(*)(void*))glLogoDrawThread

    and I then go on my merry way to the the "SetLayeredWindowAttributes@16" issue again.

  10. #10
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Originally posted by josh_d
    and I then go on my merry way to the the "SetLayeredWindowAttributes@16" issue again.
    You're not trying to use the function with win9x are you (min os: win 2000)?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  11. #11
    Registered User
    Join Date
    Mar 2004
    Posts
    17
    No sir,
    Win2k pro.

  12. #12
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Thread moved to Windows board

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, 10:18 AM