Menu

Linker cannot fine CreateStatusWindow API

Joe
2007-12-28
2012-09-26
  • Joe

    Joe - 2007-12-28

    Dev-C++ 4.9.9.2
    Windows XP Home
    I'm trying to add a status bar to the Dev-C++ example program WinMenu.cpp: The compiler can't seem to find the API function CreateStatusWindow

    I added this header (because one of the windows header files was redefining it to
    CreateStatusA which the compiler also couldn't find):

    HWND CreateStatusWindow(
    
    LONG style,     
    LPCTSTR lpszText,   
    HWND hwndParent,    
    UINT wID
    

    );

    And added this code to the program:

    unsigned int Ident = 0;

    CreateStatusWindow(
    WS_CHILD | WS_VISIBLE,
    "This is a Status Window",
    hwnd,
    Ident
    );

    Compiler gives me this error:
    [Linker error] undefined reference to `CreateStatusWindow(long, char const, HWND__, unsigned int)'

    Compiler log:
    Compiler: Default compiler
    Building Makefile: "C:\Dev-Cpp\ExamplesModify\WinMenuModify\Makefile.win"
    Executing make clean
    rm -f main.o WinMenu_private.res WinMenu.exe
    g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
    windres.exe -i WinMenu_private.rc --input-format=rc -o WinMenu_private.res -O coff
    g++.exe main.o WinMenu_private.res -o "WinMenu.exe" -L"C:/Dev-Cpp/lib" -mwindows
    main.o(.text+0x192):main.cpp: undefined reference to `CreateStatusWindow(long, char const, HWND__, unsigned int)'
    collect2: ld returned 1 exit status
    make.exe: *** [WinMenu.exe] Error 1
    Execution terminated

     
    • Joe

      Joe - 2007-12-30

      Thank you.
      Now I have a status bar. I think I'm understanding what you posted.
      If the Microsoft documentation specifies a library for a particular function then I should look for a gnu equivalent library.
      The linker is not the compiler. Got it. It didn't sound right when I wrote it, just didn't know why.
      Occam's razor: Yeah I'll try to remember that. Would have kept me from backtracking fixing up header files. But the Dev-C++ 'Search' function really made fixing them easy.

       
      • cpns

        cpns - 2007-12-30

        Export for all the Win32 API DLLs are provided in the form libXXX.a where Microsoft specifies XXX.lib.

        See also: http://sourceforge.net/forum/message.php?msg_id=2670009

         
    • cpns

      cpns - 2007-12-29

      The documentation ( http://msdn2.microsoft.com/en-us/library/bb760762.aspx ) specifies the use of the comctl32.lib export library for that function. In GNU teh naming convention for libraries is different so that would in fact be libcomctl32.a. Because this library is in a the default library path (specified by a -L<path> option), it can be linked with the -l (lower case-L) linker option where the lib prefix and .a extension may be ommitted.

      So add:

      -lcomctl32

      to the projects linker options.

      Your title states that the linker could not find the symbol, but then wrote about the compiler not finding it. You should be clear about the difference between compiler and linker errors. If you got as far as linking, then compilation was successful, and 'fixing' the code is generally not the solution. I would remove your 'redefinition' - the Windows header file was correct: it defines CreateStatusWindow as a macro implemented as either the Unicode or ANSI version depending upon your build character see options.

      Occam's razor should be applied in such situations - which is the most likely: (1) the Win32API header used my millions around the world is wrong, or (2) something else.

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.