Question:
c++ crypto PP error help?
Joe Cat
2011-12-16 19:02:43 UTC
i am trying to use cryptoPP, DES encryption library in visual studio c++ express 2010. but when i compile my main function code, i have errors saying "link unresolved external symbols"

this is my main function
when i compile this line, i have errors

#include "des.h" //cryptoPP library
#include "modes.h"
int main ()
{
cout<<"Hello"<CryptoPP::DES::Encryption desEnc (key , CryptoPP::DES::Default_keylength);
}

but without declaring the value "desEnc" as below, i can compile and the word "hello" comes out
int main ()
{
cout<<"hello"<CryptoPP::DES::Encryption;
}

could anyone help me how can i fix the errors? Thanks
Four answers:
husoski
2011-12-16 19:36:32 UTC
You need to add the .lib file to your project.



If you built it from source with a VS project, you can just add that project as a dependency, and VS will figure out which .lib file to include (debug or release) based upon the build type.



If you just have the object library in a .lib file stored someplace, you need to:



1. Add the directory containing the .lib file to your list of places to search, if it's not already in a standard place. Right-click on the project and select Properties. Under "Linker" click "General", in the "Additional Library Directories" box, click the [...] button and paste the full path name of the directory into the window (or click the [...] button in THAT window and navigate to it. Click OK. (You can leave properties open for the next step, though.)



2. Add the library filename as a dependency. In the project properties (see above) under "Linker", click "Input". In the "Additional Dependencies" box, type the names of the libraries (des.lib or whatever it is). Separate multiple file names with commas. Click OK.



Now rebuild, and the linker should find everything it needs.



The first answerer doesn't read the answers much here. You can often get more focused help at places like stackoverflow.com, codeproject.com, cppreference.com, cprogramming.com and such, but there are some pretty good people answering questions here, too. RatchetR, for example, is #3 on the BA list here, and answers mostly developer questions in various languages. There are many more.
Ratchetr
2011-12-17 03:35:40 UTC
Your code is compiling fine.

It is the linker that is generating the error.



The linker runs *AFTER* all your C++ code has been compiled. It is the job of the linker to 'stitch together' all the pieces that go into a program. The pieces might come from object files generated by the C++ compiler, or they might come from library or DLL files that you link with.



The error is saying that the linker couldn't find some items, probably CryptoPP::DES::Encryption. You need to provide the code for CryptoPP::DES::Encryption to the linker, either by compiling the C++ module that contains that code, or by linking with a library or DLL that contains the implementation of CryptoPP::DES::Encryption.



I'm not familiar with cryptoPP, so I don't know which method they support (or maybe they support both). You need to look at the docs for cryptoPP and see what the recommended way is.
Ronnoc
2011-12-17 03:05:11 UTC
Ive never worked with crypto but Id taje this to cplusplus.com, those guys know their stuff. Yahoo answers is not the place for programming q's.
anonymous
2011-12-17 03:31:07 UTC
did you link with the libraries?

you need to specify the pathname of where the libraries are located





menu:

project->properties->configuration properties->linker->general->add additional library paths

project->properties->configuration properties->linker->input: there you can add your *.lib


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...