undefined reference to `__imp_CreateSolidBrush'


Trying to use CreateSolidBrush to change a window background color.
I’ve included wingdi.h, I believe I’ve linked gdi32.lib ( however I converted gdi32.lib to a gdi32.a by using LIB2A, and I wonder if this may be an issue? ).

I wouldn’t mind using another function but I worry this could be come a re-occuring issue if I’m not able to find a solution.

Some relevant code:

#include <stdio.h> 
#include <windows.h>
#include <wingdi.h>

#include <main.h>

DWORD CreateMainWindow(void)

    WNDCLASSEXA WindowClass = { 0 };

    WindowClass.hbrBackground = CreateSolidBrush(RGB(200, 200, 200));


I use a function to easily compile

int Compile()

        int result = 0;

        char *include = "C:\\Users\\Coding\\C\\src\\include";
        char *link = "C:\\Users\\Coding\\C\\src\\lib";
        char command[256];
            "gcc -o main -I%s  -l gdi32 -L%s main.c", include, link) >= sizeof(command))
            //exception catching and handling

        return result;

I have no reason to believe the file isn’t being linked as I’m not receiving an error.

Also I’m only using Notepad++, mingw64, and command prompt.


Well the answer was extremely simple, linkages and includes must come after the file.

C:\User> gcc main.c -lgdi32 -I<include path> -o main

If this was obvious then I apologize, hopefully this helps another confused individual

Answered By – GHades

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published