对 CryptoPP::AlignedAllocate(unsigned int) 的未定义引用 [英] Undefined reference to CryptoPP::AlignedAllocate(unsigned int)
问题描述
我在 c++ linux 中使用 crypto++.这是我的简单代码:
I am using crypto++ in c++ linux. Here is my simple code:
#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] << " ";
}
}
}
}
当我运行它时,发生了一些错误:
When I run it , some error occured:
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)'
然后,我使用命令
gcc -o test test.cpp -L/usr/lib/crypto++ -lcrypto++
但是这个错误仍然存在:
but this error still there :
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)'
我该如何解决这个错误?我的代码有问题吗?
How can I fix this error? Is there something wrong with my code?
我正在为此包使用突触包管理器安装crypto++:
I am installing crypto++ using synaptic package manager for this package:
libcrypto++-utils
libcrypto++8
libcrypto++8-dbg
libcrypto++-dev
libcrypto++-doc
和 libcrypto++.a 和 libcrypto++.so 可以在/usr/lib/中找到
and libcrypto++.a and libcrypto++.so can be found in /usr/lib/
提前致谢.
推荐答案
这个命令看起来不对:
gcc -o test test.cpp -L/usr/lib/crypto++ -lcrypto++
如果(如你所说)库在 /usr/lib
中,那么你不应该说 -L/usr/lib/crypto++
If (as you say) the libs are in /usr/lib
then you shouldn't be saying -L/usr/lib/crypto++
我认为 libcrypto++8
包将其库安装在 -L/usr/lib/crypto++
目录中,并且大概它们不兼容并且不提供程序需要的未定义符号.
I think the libcrypto++8
package installs its libs in the -L/usr/lib/crypto++
directory, and presumably they are incompatible and don't provide the undefined symbols your program needs.
你应该简单地编译:
gcc -o test test.cpp -lcrypto++
(无需说 -L/usr/lib
因为它是库的默认位置)
(There's no need to say -L/usr/lib
as it's the default location for libraries anyway)
这篇关于对 CryptoPP::AlignedAllocate(unsigned int) 的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!