I am trying to compile some WinAPI code using gcc compiler. However whenever I call functions like CreateSemaphoreEx, CreateMutexEx (and some other Ex functions) I get "undefined reference to 'CreateSemaphoreEx'" link error. It works with CreateSemaphore or CreateMutex but not the Ex versions of these functions.
First I compiled with mwindows flag as such (gcc main.c -mwindows) Then I tried linking to the library manually (gcc -lkernel32 main.c) I have also tried using CreateSemaphoreExA
I also tried uninstalling and reinstalling mingw-w64 and even tried switching to TDM-GCC
I know if I change it to CreateSemaphore call it works, however I want to use the Ex version.
#include <windows.h>
int main(int argc, char** argv)
{
int initial_count = 0;
int maximum_count = 5;
HANDLE semaphore = CreateSemaphoreEx(0, initial_count, maximum_count, NULL, 0, SYNCHRONIZE | SEMAPHORE_MODIFY_STATE);
}
How can I get access to these WinAPI functions using gcc compiler on Windows (if it is at all possible).
-------- Complete Compiler Output ---------
main.c: In function 'main':
main.c:8:21: warning: implicit declaration of function 'CreateSemaphoreEx'; did you mean 'CreateSemaphoreA'? [-Wimplicit-function-declaration]
HANDLE semaphore = CreateSemaphoreEx(0, initial_count, maximum_count, NULL, 0, SYNCHRONIZE | SEMAPHORE_MODIFY_STATE);
^~~~~~~~~~~~~~~~~
CreateSemaphoreA
main.c:8:21: warning: initialization of 'HANDLE' {aka 'void *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
C:\Users\Nexwave\AppData\Local\Temp\cc3ncRYX.o:main.c:(.text+0x49): undefined reference to `CreateSemaphoreEx'
collect2.exe: error: ld returned 1 exit status
Edit 1: I know about linking. My question is whether the kernel32 library used by mingw-w64 different than one used by Microsoft's linker. And if it is different then why is there no definition for CreateSemaphoreEx (and some other Ex functions) that are available in the actual Kernel32.lib