对于代码:
#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;
}编译时出现以下错误:$:g++ test.cpp -o tess -lcrypto++ -lpthread
/tmp/ccLR085h.o: In函数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 toCryptoPP::AlignedAllocate(unsigned int)‘test.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKvCryptoPP::AllocatorWithCleanup::allocate(unsigned int,void const*)+0x38):未定义的对CryptoPP::UnalignedAllocate(unsigned int)' /tmp/ccLR085h.o: In functionCryptoPP::AllocatorWithCleanup::deallocate(void*,unsigned int)':test.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvjCryptoPP::AllocatorWithCleanup::deallocate(void*,unsigned int)+0x25):对CryptoPP::AlignedDeallocate(void*)' test.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvj[CryptoPP::AllocatorWithCleanup<unsigned char, true>::deallocate(void*, unsigned int)]+0x32): undefined reference toCryptoPP::UnalignedDeallocate(void*)’collect2的未定义引用: ld返回1个退出状态
需要帮助。THX
发布于 2011-05-11 06:22:10
这一点很棘手。我怀疑您发布的编译行不是产生错误的编译行。当我这样做的时候
g++ test.cpp -o tess -lcryptopp -lpthread -L.我没有收到任何错误,但当我收到错误时
g++ -o tess -lcryptopp -lpthread -L. test.cpp我从一开始就收到了很多错误
/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*)'这看起来像是你得到的错误。
请注意,我从源代码编译了cryptopp 5.6.1,并在本例中使用的目录中放置了库的副本:因此,我需要-L.将当前目录包括在库路径搜索中。我也在使用-lcryptopp而不是-lcrypto++,因为它是我的源码生成的。
https://stackoverflow.com/questions/4602996
复制相似问题