对CryptoPP::AlignedAllocate(unsigned int)的未定义引用
Undefined reference to CryptoPP::AlignedAllocate(unsigned int)
我在c++linux中使用crypto++。这是我的简单代码:
#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] << " ";
}
}
}
}
当我运行它时,出现了一些错误:
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++
但这个错误仍然存在:
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)'
如何修复此错误?我的代码有问题吗?
我正在使用突触包管理器为这个包安装crypto++:
libcrypto++-utils
libcrypto++8
libcrypto++8-dbg
libcrypto++-dev
libcrypto++-doc
libcrypto++.a和libcrypto++.so可以在/usr/lib/中找到
提前谢谢。
此命令看起来错误:
gcc -o test test.cpp -L/usr/lib/crypto++ -lcrypto++
如果(正如你所说)库在/usr/lib
中,那么你不应该说-L/usr/lib/crypto++
我认为libcrypto++8
包将其库安装在-L/usr/lib/crypto++
目录中,可能它们是不兼容的,并且没有提供程序所需的未定义符号。
您应该使用以下代码进行编译:
gcc -o test test.cpp -lcrypto++
(不需要说-L/usr/lib
,因为它是库的默认位置)
它解决了!我将命令更改为:
g++ -o test test.cpp -L/usr/lib/crypto++ -lcrypto++
到该命令:
g++ -o test test.cpp -L/usr/lib/ -lcryptopp -lpthread
我添加-lpthread是因为在我使用以下命令之后:
g++ -o test test.cpp -L/usr/lib/ -lcryptopp
我得到这些错误:
./libcryptopp.so: undefined reference to `pthread_getspecific'
./libcryptopp.so: undefined reference to `pthread_key_delete'
./libcryptopp.so: undefined reference to `pthread_key_create'
./libcryptopp.so: undefined reference to `pthread_setspecific'
我误解了-L/usr/lib/crypto++arg,我以为编译器会在/usr/lib/dir中搜索crypto++,结果编译器会在-L/usr/lib/corypto++目录中搜索crupto++,而安装在-L/usr/lib/dir中的包。
感谢@jonathan wakely。
我也有这个问题。你的编译器需要将库文件绑定到你的程序,因为它找不到你的decation的任何实现!
我仍然没有解决我的问题。但你还有别的办法!!!您可以将.cpp
原始文件替换为库文件。
您可以从以下链接下载Cryptopp
:
https://www.cryptopp.com/cryptopp563.zip
相关文章:
- C++ std::vector<int> 体系结构的未定义符号 x86_64:
- 对'cv::VideoCapture::VideoCapture(int)的未定义引用
- 编译Qt项目给出了对运算符delete(void*,unsigned int)的未定义引用
- 从emxArray_uint8_T检测到错误:.text+0xc1):未定义对"emxInit_uint8_T1(emxArray_uint8_T**, int)"的引用?
- 对 'i2c_smbus_read_word_data(int, 无符号字符)的未定义引用
- 未定义模板'std::__1::function<int (double, double, double, double)>'的隐式实例化
- 创建具有未定义溢出的无符号 int
- 对ISPRIME(INT)的未定义引用,但已定义
- Cpp 未定义引用 'Apache:: thrift:: transport:: TSocket:: TSocket (std:: string const&, int)'
- gtest - 未定义对"testing::InitGoogleTest(int*, char**)"的引用
- 对"displayForStudent(int, int const*, double const*, int)"的未定义引用 collect2.exe:错误:ld 返回 1 个退出状态
- 对 'WindowProc(HWND__*, unsigned int, unsigned int, long)@16' 的未定义引用
- Qt5 对'QApplication::QApplication(int&, char**, int)'的未定义引用
- 如果没有未定义的行为 [c++],哪些浮点值无法转换为 int?
- std::is_arithmetic 为通用 lambda 中的 int 类型返回 false:未定义的行为?
- 使用未定义它们的构造函数(矩阵(int,int))给出atribute 值
- C++ 链接器错误未定义对"Suma(int, int)"的引用 ld 返回 1 个退出状态
- shared_ptr中对const int的未定义引用
- 对'std::string Helper::ToString<int>(int const&)'的未定义引用
- 对"Math::addNumbers(int, int)"的未定义引用