0

I installed msys2 and I'm using the UCRT64 environment that comes with it. I installed the mingw-w64-ucrt-x86_64-toolchain group of packages, which I am using to compile C++.

I have a file which compiles as a static library libtestwin64.a and contains this:

#include <windows.h> // contains <winuser.h> <wingdi.h>

void funcA() {
    HDC dc = GetDC(NULL); // references to <winuser.h> cause no error. 
    HCOLORSPACE hcs = GetColorSpace(dc); // references to <wingdi.h> cause error. 
}

When I try to link with libtestwin64.a and compile an executable g++ -I../mirr/inc obj/Win64/three.o obj/Win64/four.o -o ../bin/test64.exe -luser32 -lgdi32 -L../mirr/lib -ltestwin64, it causes these undefined reference errors for anything from wingdi.h:

D:/software/msys/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: 
../mirr/lib/libtestwin64.a(one.o):one.cpp:(.text+0xfd): undefined reference to `__imp_GetColorSpace'

ld.exe reports no error about finding the files libgdi32.a etc. Adding options like -lgdi32 to the linker doesn't change the result. Other system libraries like libuser32.a cause no error.

What can I do to use functions from Windows GDI through msys2?

user193661
  • 879
  • 10
  • 29
  • Was `libtestwin64.a` compiled using the same toolchain? – M.M Jan 09 '23 at 05:04
  • @M.M yes like `ar rs ../lib/libtestwin64.a obj/Win64/one.o obj/Win64/two.o` `g++ -I../inc -Wall -pipe -fno-exceptions -fno-rtti -fstrict-aliasing -m64 -MMD -c one.cpp -o obj/Win64/one.o -MT obj/Win64/one.o` – user193661 Jan 09 '23 at 05:09
  • 1
    Linking order issue, perhaps? Reorder `-ltestwin64` before `lgdi32`. – HolyBlackCat Jan 09 '23 at 05:39

0 Answers0