3

I wrote the following code snippet in VS2010:

#pragma once
#include "stdafx.h"
#ifndef SECURITY_WIN32
#define SECURITY_WIN32
#endif
#include "windows.h"
#include "sspi.h"

int main( void )
{
    ULONG cPackages = 0;
    PSecPkgInfo pInfo = NULL;
    SECURITY_STATUS stat = EnumerateSecurityPackages(&cPackages, &pInfo);
    if (stat == SEC_E_OK) 
    { 
        for (ULONG i = 0; i < cPackages; i++) 
        { 
            wprintf(L"%s\t%s\n",pInfo[i].Name, pInfo[i].Comment); 
        } 
        FreeContextBuffer(pInfo); 
    } 
    return 0; 

}

but, at the compile time I got the following errors:

error LNK2019: unresolved external symbol _imp_EnumerateSecurityPackagesW@8 referenced in function _main

and

error LNK2019: unresolved external symbol _FreeContextBuffer@4 referenced in function _main

can anyone please help me?

RRR
  • 3,937
  • 13
  • 51
  • 75

3 Answers3

6

You need to link against Secur32.lib.

Go to Project Properties -> Linker -> Input and add Secur32.lib in the list.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
2

Linking errors "unresolved external symbol", generally, mean that there were no required library (libraries) added to resolve the symbol. In VC++ case you get the symbol without decoration FreeContextBuffer (which will be the function missed), go to http://msdn.microsoft.com and search for this function's related article. In this case it will produce "FreeContextBuffer" as a first result. You then look for the last section "Requirements" and find out what headers would be needed for compiler and libraries (your case) for linker- Secur32.lib. Then, add this library in IDE's Properties -> Linker -> Input. Or with #pragma comment() directive in code. Hope this will help.

SChepurin
  • 1,814
  • 25
  • 17
  • Not really, it could also mean unimplemented functions, or wrong use of import/export directives. – Luchian Grigore Mar 26 '12 at 14:31
  • Oh yes, but these are "advanced" causes, that imply the programmer already knows what library is needed. Anyway, i will add "generally" to the answer. – SChepurin Mar 26 '12 at 14:55
  • I know the causes that I mentioned weren't the source, but it was also wrong saying the error means one thing when it can mean more. The new version of the answer is much more correct. +1 – Luchian Grigore Mar 26 '12 at 15:07
0
#include "stdafx.h"

was meant for including 'system' interfaces, it's likely that windows.h it's already included. So try to move your #define inside the stdafx.h, before any other include.

CapelliC
  • 59,646
  • 5
  • 47
  • 90