Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CryptAcquireContext -- unresolved external

I'm linking with a third-party library (Poco C++) and getting the following unresolved symbol errors from the linker. It appears to be unable to find "CryptAcquireContextW", "CryptReleaseContext", and "CryptGenRandom".

According to the Microsoft information here, these functions are linkable using "Advapi32.lib". I've added that to my linker inputs but the symbols remain unresolved.

1>PocoFoundationCLR.lib(RandomStream.obj) : error LNK2019: unresolved external symbol __imp__CryptAcquireContextW@20 referenced in function "public: virtual int __thiscall Poco::RandomBuf::readFromDevice(char *,__int64)" (?readFromDevice@RandomBuf@Poco@@UAEHPAD_J@Z)

1>PocoFoundationCLR.lib(RandomStream.obj) : error LNK2019: unresolved external symbol __imp__CryptReleaseContext@8 referenced in function "public: virtual int __thiscall Poco::RandomBuf::readFromDevice(char *,__int64)" (?readFromDevice@RandomBuf@Poco@@UAEHPAD_J@Z)

1>PocoFoundationCLR.lib(RandomStream.obj) : error LNK2019: unresolved external symbol __imp__CryptGenRandom@12 referenced in function "public: virtual int __thiscall Poco::RandomBuf::readFromDevice(char *,__int64)" (?readFromDevice@RandomBuf@Poco@@UAEHPAD_J@Z)

I've verified that Advapi32.lib is on the search path and Advapi32.dll is in the Windows directory, so I'm not sure how this error continues to happen.

Ideas, anyone?

Thanks!

like image 377
Bungles Avatar asked Jun 03 '15 00:06

Bungles


People also ask

How do you fix unresolved externals?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

What does unresolved externals mean?

Unresolved external references occur when the symbol for a function or global variable is referenced in a program, but none of the object files or libraries specified in the link step contain a definition for that symbol.


1 Answers

Although I can't readily explain why this worked, here's what did.

The project that was failing had "Advapi32.lib" listed in the "Inherited" section of the linker inputs, but apparently wasn't actually being linked in.

I added "Advapi32.lib" to the "additional libraries" section and somehow that caused it to be picked up and linked with properly.

I'm going to write it off as just a difference in how VS 2013 was installed on the two PCs, but it's still a curious oddity.

like image 140
Bungles Avatar answered Sep 19 '22 09:09

Bungles