Betlander
Betlander

Reputation: 45

Undefined reference to CreateProcessWithLogonW

So I've been working on a small app that at some runs runs an application as another user, I'm writing it in C and using the MinGW GCC compiler to compile and link it. My issue is that whenever I try to use the WINAPI function CreateProcessWithLogonW() I get an error that says "Undefined reference to CreateProcessWithLogonW()."

This is in spite of the fact that I link the Advapi32 when I compile it like so,

gcc file.c -lAdvApi32 -o filename

Upvotes: 1

Views: 525

Answers (2)

AgentLiquid
AgentLiquid

Reputation: 3682

The correct solution is to actually #include the correct mingw32 headers: i.e.

#include <windows.h>

Though the solution that Anthales proposed works, it doesn't scale well.

Upvotes: 2

Anthales
Anthales

Reputation: 1148

Try linking with the dll in question directly, like so:

gcc file.c %windir%\system32\advapi32.dll -o filename

When you use the switch -lAdvApi32 instead, you will link with libadvapi32.a from MinGW/lib. Sadly, I can't answer why this won't work; maybe this lib is outdated, or has a completely different meaning

Upvotes: 0

Related Questions