Undefined reference to __imp_Rectangle in C++

I have been having trouble compiling some code in C++.

Code:

#include <windows.h>

LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int nShowCmd )
{

    static char name[] = "My Application";
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    // Step 1: Registering the Window Class
    wc.cbSize = sizeof( WNDCLASSEX );
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    wc.hbrBackground = ( HBRUSH ) ( COLOR_WINDOW + 1 );
    wc.lpszMenuName = NULL;
    wc.lpszClassName = name;
    wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );

    if ( !RegisterClassEx( & wc ) )
    {

        MessageBox( NULL, "Window Registration Failed!", "Registration Failure", MB_ICONEXCLAMATION | MB_OK );

        return 0;

    }

    // Step 2: Creating the Window
    hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, name, "My First Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 400, NULL, NULL, hInstance, NULL );

    ShowWindow( hwnd, nShowCmd );
    UpdateWindow( hwnd );

    // Step 3: The Message Loop
    while( GetMessage( & Msg, NULL, 0, 0 ) > 0 )
    {

        TranslateMessage( & Msg );

        DispatchMessage( & Msg );

    }

    return ( int )Msg.wParam;

}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{

    HDC hdc;
    PAINTSTRUCT ps;
    RECT rect;

    switch( msg )
    {

        case WM_PAINT:

            hdc = BeginPaint( hwnd, & ps );

            GetClientRect( hwnd, & rect );

            Rectangle( hdc, rect.right / 2 - 50, rect.bottom / 2 - 20, rect.right / 2 + 50, rect.bottom / 2 + 20 );

            DrawText( hdc, "Hello World!", -1, & rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER );

            EndPaint( hwnd, & ps );

            break;

        case WM_CLOSE:

            DestroyWindow( hwnd );

            break;

        case WM_DESTROY:

            PostQuitMessage( 0 );

            break;

    }

    return DefWindowProc( hwnd, msg, wParam, lParam );

}

The tutorial I am following says that it compiles correctly with no problems, but this is what my compiler looks like:

NPP_EXEC: "Compile C++ File"
NPP_SAVE: G:\C++\src\Win32\Hello World! Window.cpp
g++ -o "G:\C++\src\Win32\Hello World! Window" "G:\C++\src\Win32\Hello World! Window.cpp" -static
Process started >>>
C:\Users\Braeden\AppData\Local\Temp\cc3N4Ls1.o:Hello World! Window.cpp:(.text+0x29b): undefined reference to `__imp_Rectangle'
collect2.exe: error: ld returned 1 exit status
<<< Process finished.
================ READY ================

I am not using any popular IDE. I am using Notepad++ as a text editor and a MinGW distro as my compiler. I am on Win7 x64. Could someone tell me what I am doing wrong?

Answers


Rectangle is provided by Gdi32.dll. You should be linking against Gdi32.lib.


Need Your Help

API Facebook - Get all profiles pictures (not only /picture) of a user (different of /me)

facebook facebook-graph-api facebook-fql

I need your help because I'm trying to collect all the profil pictures - per user - of a list of users who are :

Zend Framework doesn't show errors

php exception zend-framework frameworks

Every error that happens in the server is not shown to me... I tried checking the requisitions in Firebug, but everytime when there is an error, the response fails.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.