Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link error for Windows functions

I'm trying to test if standard library (kernel32.dll) have one of the function.

Code snippet for test:

extern void CreateProcessA (void);
int
main (void)
{
  CreateProcessA ();
  return 0;
}

The code compiles and links as follow:

cl /c test.c
link test.obj kernel32.lib

This code can be compiled well with Visual C++, but cannot link:

test.obj : error LNK2019: unresolved external symbol _CreateProcessA referenced in function _main

But function CreateProcessA does exists in kernel32.dll, you no?

How to link it properly?

P.S. I don't want to run this code, just check that function exists (if code compiles and links - function exists).


1 Answers

To see if the function exists, you use

dumpbin /exports kernel32.dll | findstr CreateProcess

You didn't even use the right prototype, so of course the linker can't find the correct function. The naming convention is completely off, and CreateProcess is really a macro (that expands to either CreateProcessA or W depending on UNICODE).

(You don't need to link against kernel32.lib explicitly as that's already done by default by cl.exe)

Instead of declaring the prototype yourself, #include <windows.h>.

like image 52
Alex Budovski Avatar answered Sep 26 '26 00:09

Alex Budovski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!