Communication error 2019 - C ++

I wrote the following piece of code in VS2010:

#pragma once
#include "stdafx.h"
#ifndef SECURITY_WIN32
#define SECURITY_WIN32
#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); 
    return 0; 



but during compilation I got the following errors:

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


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

Can anyone help me?


source to share

3 answers

You need to associate with Secur32.lib


Go to Project Properties -> Linker -> Input

and add Secur32.lib

to the list.



Linking "unresolved external symbol" errors generally means that the required library (s) were not available to resolve the symbol. In the case of VC ++, you get an unadorned character FreeContextBuffer

(which will be missed by the feature), go to and search for that feature. In this case, it will produce "FreeContextBuffer" as the first result. Then you look for the last section "Requirements" and find out what headers the compiler and libraries (your case) need for linker-Secur32.lib. Then add this library in properties of IDE -> Linker -> Input. Or with a directive #pragma comment()

in your code. Hope this helps.



#include "stdafx.h"


was meant to enable "system" interfaces, it is likely that windows.h is already enabled. So try moving the #define inside stdafx.h before including everything else.



All Articles