2011-01-05 5 views
2

Für den Code:libcrypto ++ in Linux

#include <fstream> 

#include <iostream> //cryptopp libraries 

#include "cryptopp/dll.h" 

#include "cryptopp/default.h" 


using namespace std; 

using namespace CryptoPP; 

int main() 
{ 

byte key[AES::DEFAULT_KEYLENGTH], iv[AES::BLOCKSIZE]; 

    // initialize key and iv here 

    CFB_Mode<AES >::Encryption cfbEncryption(key, AES::DEFAULT_KEYLENGTH, iv); 

std::cout << "Hello world!" << std::endl; 

return 0; 

} 

ich die folgenden Fehler, wenn es kompiliert: $: g ++ test.cpp -o tess -lcrypto ++ -lpthread

/tmp/ccLR085h.o :. In Funktion CryptoPP::AllocatorWithCleanup<unsigned char, true>::allocate(unsigned int, void const*)': test.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv[CryptoPP::AllocatorWithCleanup<unsigned char, true>::allocate(unsigned int, void const*)]+0x2b): undefined reference to CryptoPP :: AlignedAllocate (unsigned int)‘ test.cpp :(text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv [CryptoPP AllocatorWithCleanup :: :: zuteilen (unsigned int, ungültig const *)] + 0x38): undefined Bezug auf CryptoPP::UnalignedAllocate(unsigned int)' /tmp/ccLR085h.o: In function CryptoPP: : AllocatorWithCleanup :: deallocate (void *, unsigned int) ': test.cpp :(text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvj [CryptoPP AllocatorWithCleanup :: :: DEALLOCATE (void *, unsigned int)] + 0x25). Undefinierten Bezug auf CryptoPP::AlignedDeallocate(void*)' test.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvj[CryptoPP::AllocatorWithCleanup<unsigned char, true>::deallocate(void*, unsigned int)]+0x32): undefined reference to CryptoPP :: UnalignedDeallocate (void *)‘ collect2: ld ergab 1 Ausfahrt Status

BRAUCHEN SIE HILFE. THX

Antwort

0

Dieser ist knifflig. Ich vermute, dass die von Ihnen gepostete Kompilierungszeile nicht die Kompilierungszeile ist, die die Fehler verursacht hat. Als ich

g++ test.cpp -o tess -lcryptopp -lpthread -L. 

bekomme ich keine Fehler, aber wenn ich

tun
g++ -o tess -lcryptopp -lpthread -L. test.cpp 

Ich bekomme eine Menge von Fehlern mit

/tmp/ccCSTBSy.o: In function `CryptoPP::SimpleKeyingInterface::SimpleKeyingInterface()': 
SO4602996.cpp:(.text._ZN8CryptoPP21SimpleKeyingInterfaceC2Ev[CryptoPP::SimpleKeyingInterface::SimpleKeyingInterface()]+0x4): undefined reference to `vtable for CryptoPP::SimpleKeyingInterface' 
/tmp/ccCSTBSy.o: In function `CryptoPP::SecBlock<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, false> >::SecBlock(unsigned int)': 
SO4602996.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*)' 

beginnen, die wie die Fehler sieht das Sie bekommen.

Bitte beachten Sie, dass ich cryptopp 5.6.1 aus Quelle kompiliert habe und eine Kopie der Bibliothek in das Verzeichnis, das ich für dieses Beispiel verwende, gelegt habe: ich brauche -L., um das aktuelle Verzeichnis in die Bibliothekspfadsuche aufzunehmen. Ich verwende auch -lcryptopp anstelle von -lcrypto++, weil das, was meine Quelle produziert.