Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2019 link error - c++ [duplicate]

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?

like image 585
RRR Avatar asked May 04 '26 12:05

RRR


2 Answers

You need to link against Secur32.lib.

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

like image 134
Luchian Grigore Avatar answered May 07 '26 00:05

Luchian Grigore


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.

like image 26
SChepurin Avatar answered May 07 '26 01:05

SChepurin



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!