You'll need to link to cryptopp and to all its dependencies.

So make that
-lcryptopp -lpthread

and other libs it might need (just look up those undefined symbols and
find out which library are they from).

On Jul 27, 4:38 am, "saeed.gnu" <[email protected]> wrote:
> Hello
> I will a simple code to encrypt and decrypt a string. I wrote
> following Code:
>
> __________________________________________________________
> #include <iostream>
> #include <stdlib.h>
> //#include <cryptopp/cryptlib.h>
> #include <cryptopp/default.h>
> #include <cryptopp/hex.h>
> //#include "cryptopp/modes.h"
> //#include "cryptopp/aes.h"
>
> using namespace CryptoPP;
>
> using namespace std;
>
> // encode a string using passPhrase and encode it in hex
> // returns the ciphertext, which should be deleted by caller
> char *EncryptString(const char *instr, const char *passPhrase) {
>   unsigned int len=strlen(instr);
>   char* outstr;
>
>   DefaultEncryptor encryptor(passPhrase, new HexEncoder);
>   //DefaultEncryptorWithMAC encryptor(passPhrase, new HexEncoder);
>   encryptor.Put((byte *)instr, len);
>   encryptor.MessageEnd();
>
>   unsigned int outputLength = encryptor.MaxRetrievable();
>   outstr = new char[outputLength+1];
>   encryptor.Get((byte *)outstr, outputLength);
>   outstr[outputLength] = 0;
>   return outstr;
>
> }
>
> int main()
> {
>   //cout << crypt("firstpas", "as"); << "\n";
>   cout << EncryptString("test string", "passwd") << "\n";
>   return 0;}
>
> __________________________________________________________
>
> And tried to compile it with g++ (without any command options, is
> there needed any?)
> I use GNU/Linux(Ubuntu 8.10).
> I tested with g++ 4.1 and 4.2 and 4.3. but I get a long error output
> that says undefined reference to `CryptoPP::....
>
> A part of error:
>
> /tmp/ccZbCSRe.o: In function `EncryptString(char const*, char
> const*)':
> crypt-test.cpp:(.text+0x138): undefined reference to
> `CryptoPP::DefaultEncryptor::DefaultEncryptor(char const*,
> CryptoPP::BufferedTransformation*)'
> crypt-test.cpp:(.text+0x34d): undefined reference to
> `CryptoPP::BufferedTransformation::MaxRetrievable() const'
> crypt-test.cpp:(.text+0x37d): undefined reference to
> `CryptoPP::BufferedTransformation::Get(unsigned char*, unsigned int)'
> /tmp/ccZbCSRe.o: In function `CryptoPP::SecBlock<unsigned char,
> CryptoPP::AllocatorWithCleanup<unsigned char, false> >::SecBlock
> (unsigned int)':
> crypt-test.cpp:
> (.text._ZN8CryptoPP8SecBlockIhNS_20AllocatorWithCleanupIhLb0EEEEC1Ej
> [CryptoPP::SecBlock<unsigned char,
> CryptoPP::AllocatorWithCleanup<unsigned char, false> >::SecBlock
> (unsigned int)]+0x25): undefined reference to
> `CryptoPP::AllocatorWithCleanup<unsigned char, false>::allocate
> (unsigned int, void const*)'
> /tmp/ccZbCSRe.o: In function `CryptoPP::SecBlock<unsigned char,
> CryptoPP::AllocatorWithCleanup<unsigned char, false> >::~SecBlock()':
>
> And when I give option "-lcryptopp" to g++, running command:
> g++ crypt-test.cpp -lcryptopp
> Then I get this error (newly after previous like long error):
>
> /usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/libcrypto++.so:
> undefined reference to `pthread_key_create'
> /usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/libcrypto++.so:
> undefined reference to `pthread_getspecific'
> /usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/libcrypto++.so:
> undefined reference to `pthread_key_delete'
> /usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/libcrypto++.so:
> undefined reference to `pthread_setspecific'
> collect2: ld returned 1 exit status
>
> Please help me. Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Reply via email to