0

I need to use some functions from the Win32 Crypto API, such as CryptQueryObject. The problem is that I also need to compile my program with MingW and the crypto library included is missing some of the functions that I need, like the aformentioned CryptQueryObject. I tried copying the relevant C header definitions, so that the program now compiles, but at link time it fails with undefined reference errors (since mingw's crypt32.dll doesn't implement some functions). I tried linking against C:\Windows\System32\crypt32.dll, but it still returns linking errors.

Is there a way to use the entire Crypto API in mingw?

Stefano
  • 126
  • 2
  • 7

3 Answers3

1

You need to dynamically link to crypt32.dll. You can either do this at runtime using Win32 API functions LoadLibrary + GetProcAddress, or at compile time using an import library.

For runtime binding, MSDN has a good example.

EDIT: If you need a bunch of API functions not present in MinGW's headers, go for the import library.

Koliw
  • 28
  • 1
  • 6
user1071136
  • 15,636
  • 4
  • 42
  • 61
0

I had the same problem. Download and install the Windows SDK.

Now call the linker:

gcc -L"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.14393.0\um\arm" -o "Test"  ./main.o -lcrypt32
Jonny Schubert
  • 1,393
  • 2
  • 18
  • 39
  • No, don't mix MinGW with Microsoft's SDK. That will mess up things more as there are 2 different implementations that should bot be mixed. – Brecht Sanders Apr 13 '23 at 11:52
0

Maybe you are using an old version of MinGW, because the crypto stuff is present in recent versions like MinGW-w64. Get the latest version via MSYS2's package manager pacman or use a standalone build from https://winlibs.com

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40