October 23, 2024
Chicago 12, Melborne City, USA
C++

mingw32: undefined reference to `__imp_ChoosePixelFormat' despite linking -lgdi32


I can’t get ChoosePixelFormat to link. I’m using x86_64-w64-mingw32-gcc on ubuntu. I have simplified to this example that reproduces the error for me:

#include <windows.h>
#include <GL/gl.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nCmdShow)
{
    static PIXELFORMATDESCRIPTOR pfd = {};
    HDC hdc = NULL;
    GLuint pixelFormat;

    if (!(pixelFormat = ChoosePixelFormat(hdc,&pfd))) {
        return 1;
    }

    return 0;
}

This is the command I run x86_64-w64-mingw32-gcc -lgdi32 src/main.c and get this error

x86_64-w64-mingw32-gcc -lgdi32 src/main.c
/usr/bin/x86_64-w64-mingw32-ld: /tmp/cc8lwfvD.o:main.c:(.text+0x31): undefined reference to `__imp_ChoosePixelFormat'
collect2: error: ld returned 1 exit status

Other functions from libgdi32 link just fine. ChoosePixelFormat doesn’t work. I’ve tried reinstalling mingw32 with no luck. I have tried searching for some other library that I should be linking on top of libgdi32 and found nothing. I’m not sure if I am missing anything obvious at this point but I can’t figure this out.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video