Estoy usando crypto ++ en C++ linux. Aquí está mi código simple:Referencia no definida a CryptoPP :: AlignedAllocate (unsigned int)
#include <iostream>
#include <fstream>
#include <string.h>
#include "crypto++/cryptlib.h"
#include "crypto++/modes.h"
#include "crypto++/filters.h"
#include "crypto++/aes.h"
#include "crypto++/osrng.h"
#include "crypto++/strciphr.h"
using namespace std;
using namespace CryptoPP;
ifstream::pos_type size;
char * memblock;
int length;
char * _iv[AES::BLOCKSIZE];
char * keys[AES::MAX_KEYLENGTH];
void encriptCTR(byte * outbyte, const byte * inbyte, const byte * key, const byte * iv);
void encriptCTR(byte * outbyte, const byte * inbyte, const byte * key, const byte * iv)
{
size_t inbyte_len = strlen((const char *)inbyte);
CTR_Mode<AES>::Encryption ctr_encription(key, strlen((const char*)key), iv);
ctr_encription.ProcessData(outbyte, inbyte, inbyte_len);
}
int main()
{
ifstream file;
file.open("testaja", ios::binary);
if (file.is_open())
{
file.seekg (0, ios::end);
length = file.tellg();
memblock = new char [length];
file.seekg (0, ios::beg);
file.read (memblock, length);
if (!file)
{
int a;
a = (int)file.gcount();
file.clear();
}
else
{
file.close();
for (int i = 0; i < length; ++i)
{
cout << hex << (int)memblock[i] << " ";
}
}
}
}
Cuando lo ejecuto, algún error ocurrió:
undefined reference to `CryptoPP::AlignedAllocate(unsigned int)'
undefined reference to `CryptoPP::UnalignedAllocate(unsigned int)'
undefined reference to `CryptoPP::AlignedDeallocate(unsigned int)'
undefined reference to `CryptoPP::UnalignedDeallocate(unsigned int)'
Entonces, he usado comandos
gcc -o test test.cpp -L/usr/lib/crypto++ -lcrypto++
pero este error sigue ahí:
undefined reference to `CryptoPP::AlignedAllocate(unsigned int)'
undefined reference to `CryptoPP::UnalignedAllocate(unsigned int)'
undefined reference to `CryptoPP::AlignedDeallocate(unsigned int)'
undefined reference to `CryptoPP::UnalignedDeallocate(unsigned int)'
¿Cómo puedo solucionar este error? ¿Hay algún problema con mi código?
Estoy instalando Crypto ++ usando el gestor de paquetes Synaptic para este paquete:..
libcrypto++-utils
libcrypto++8
libcrypto++8-dbg
libcrypto++-dev
libcrypto++-doc
y libcrypto ++ A y libcrypto ++ por lo que se pueden encontrar en/usr/lib/
Gracias de antemano.
me trataron uso g ++ para compilar, pero los errores todavía allí. ¿Qué código C++ debo vincular? Gracias. – user1533464
creo AlignedAllocate (unsigned int) usado en crypto ++/secblock.h que incluye crypto ++/misc.h donde AlignedAllocate (unsigned int) se declara, pero de alguna manera AlignedAllocate (unsigned int) implementación no encontrada, y se produjo este error. ¿que debería hacer? – user1533464
intenté incluir crypto ++/misc.h en mi programa, pero esos errores aún estaban presentes. – user1533464