Tôi đang sử dụng crypto ++ trong C++ linux. Đây là mã đơn giản của tôi:Tham chiếu không xác định đối với 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] << " ";
}
}
}
}
Khi tôi chạy nó, một số lỗi xảy ra:
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)'
Sau đó, tôi sử dụng lệnh
gcc -o test test.cpp -L/usr/lib/crypto++ -lcrypto++
nhưng lỗi này vẫn còn:
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)'
Làm cách nào để khắc phục lỗi này? Có điều gì sai với mã của tôi không?
Tôi cài đặt crypto ++ sử dụng quản lý gói synaptic cho gói này:..
libcrypto++-utils
libcrypto++8
libcrypto++8-dbg
libcrypto++-dev
libcrypto++-doc
và libcrypto ++ a và libcrypto ++ như vậy có thể được tìm thấy trong/usr/lib/
Cảm ơn trước.
tôi đã cố gắng sử dụng g ++ để biên dịch, nhưng những lỗi vẫn còn đó. Tôi nên liên kết mã C++ nào? cảm ơn. – user1533464
tôi tin rằng AlignedAllocate (unsigned int) được sử dụng trong crypto ++/secblock.h bao gồm crypto ++/misc.h trong đó AlignedAllocate (unsigned int) được khai báo, nhưng bằng cách nào đó AlignedAllocate (unsigned int) thực hiện không tìm thấy, và lỗi này xảy ra. tôi nên làm gì? – user1533464
Tôi đã cố gắng bao gồm crypto ++/misc.h trong chương trình của tôi, nhưng những lỗi đó vẫn còn bị làm mờ. – user1533464