I try to build some source code containig Win32 API code with GCC 8.3.0 (i686-posix-dwarf) that comes with Strawberry Perl Portable package. It easily builds code, but struggles when it comes to linking against Windows' core dlls:
ld.exe: CMakeFiles\ninja.dir/objects.a(util.cc.obj):util.cc:(.text+0x10ce):
undefined reference to `_imp__GetLogicalProcessorInformationEx@12'
The code was configured using CMake with following cmd:
cmake -B build -S . -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
-DCMAKE_GENERATOR="MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=gmake
-DBUILD_TESTING=OFF
After some googling, I added -DCMAKE_EXE_LINKER_FLAGS="-L\"C:\Windows\System32\" -Wl,--as-needed -lkernel32 to cmake configuration cmd and it changed error to:
ld.exe: strawberry-perl-5.32.1.1-32bit-portable/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/lib/../lib/libmingwex.a(lib32_libmingwex_a-misc.o):misc.c:(.text+0x60a):
undefined reference to `_imp__LeaveCriticalSection@4'
ld.exe: strawberry-perl-5.32.1.1-32bit-portable/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/lib/../lib/libmingwex.a(lib32_libmingwex_a-wcrtomb.o):wcrtomb.c:(.text+0x75):
undefined reference to `_imp__WideCharToMultiByte@32'
As I understand, it struggles finding Win32 dll functions and by adding -lkernel32 I helped find some missing functions, but it still cannot find them all.
Is there a way to fix undefined referece errors?
_imp__LeaveCriticalSection@4is a 32 bit ABI, but you link with 64 bit kennel32.lib. Maybe you need to link with libwindowsapp.a, i.e. -lwindowsapp.-L\"C:\Windows\System32\“is nonsense, this directory doesn't contain .lib files.