由于未定义的引用,无法链接到 Debian 上的 Crypto++

Posted

技术标签:

【中文标题】由于未定义的引用,无法链接到 Debian 上的 Crypto++【英文标题】:Cannot link to Crypto++ on Debian due to undefined references 【发布时间】:2018-06-11 05:53:07 【问题描述】:

我有一个项目依赖于 Debian 8.10 上的 Crypto++。该项目有一个库(称为common,使用 Crypto++)和可执行文件(hwinfo)。我将 Cmake 用于构建目的。

这是我的库构建 Cmake:

cmake_minimum_required(VERSION 3.2.2)
set (CMAKE_CXX_STANDARD 11)
include_directories()
file(GLOB SOURCES "*.cpp")
project(common)
add_library(common $SOURCES)
find_library(LIBCRYPTOPP cryptopp)
target_link_libraries(common $LIBCRYPTOPP)
install(TARGETS common 
    ARCHIVE DESTINATION $PROJECT_SOURCE_DIR/../../lib
    LIBRARY DESTINATION $PROJECT_SOURCE_DIR/../../lib)

还有我的可执行 Cmake 文件:

cmake_minimum_required(VERSION 3.2.2)
set (CMAKE_CXX_STANDARD 11)
include_directories(../common)
file(GLOB SOURCES "*.cpp")
project(hwinfo)
add_executable(hwinfo $SOURCES)
find_library(LIBCOMMON common PATHS $PROJECT_SOURCE_DIR/../../lib)
find_library(LIBCRYPTOPP cryptopp)
message(STATUS "CRYPTO LIBRARY ===>" $LIBCRYPTOPP)
message(STATUS "MY COMMON LIBRARY ===>" $LIBCOMMON)
target_link_libraries(hwinfo $LIBCRYPTOPP $LIBCOMMON)
install(TARGETS hwinfo 
    RUNTIME DESTINATION $PROJECT_SOURCE_DIR/../../bin)

来自可执行 Cmake (message (STATUS...)) 中的诊断消息:

-- CRYPTO LIBRARY ===>/usr/local/lib/libcryptopp.a
-- MY COMMON LIBRARY ===>/home/myself/dev/common/lib/libcommon.a

因此,正在查找库。这是我在编译时遇到的错误。我已经裁剪了一些错误,否则我将无法发布,但看到所有加密调用都是未定义的:

...    
[ 64%] Linking CXX executable hwinfo
../../../lib/libcommon.a(Encryptor.cpp.o): In function `common::Encryptor::encrypt(std::string)':
Encryptor.cpp:(.text+0x2a6): undefined reference to `CryptoPP::CipherModeFinalTemplate_ExternalCipher<CryptoPP::CBC_Encryption>::CipherModeFinalTemplate_ExternalCipher(CryptoPP::BlockCipher&, unsigned char const*, int)'
Encryptor.cpp:(.text+0x2c5): undefined reference to `CryptoPP::StringSinkTemplate<std::string>::StringSinkTemplate(std::string&)'
Encryptor.cpp:(.text+0x2ed): undefined reference to `CryptoPP::StreamTransformationFilter::StreamTransformationFilter(CryptoPP::StreamTransformation&, CryptoPP::BufferedTransformation*, CryptoPP::BlockPaddingSchemeDef::BlockPaddingScheme, bool)'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `common::Encryptor::decrypt(std::string)':
Encryptor.cpp:(.text+0x477): undefined reference to `CryptoPP::CipherModeFinalTemplate_ExternalCipher<CryptoPP::CBC_Decryption>::CipherModeFinalTemplate_ExternalCipher(CryptoPP::BlockCipher&, unsigned char const*, int)'
Encryptor.cpp:(.text+0x4a5): undefined reference to `CryptoPP::StringSinkTemplate<std::string>::StringSinkTemplate(std::string&)'
Encryptor.cpp:(.text+0x4cd): undefined reference to `CryptoPP::StreamTransformationFilter::StreamTransformationFilter(CryptoPP::StreamTransformation&, CryptoPP::BufferedTransformation*, CryptoPP::BlockPaddingSchemeDef::BlockPaddingScheme, bool)'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::SimpleKeyingInterface::~SimpleKeyingInterface()':
Encryptor.cpp:(.text._ZN8CryptoPP21SimpleKeyingInterfaceD2Ev[_ZN8CryptoPP21SimpleKeyingInterfaceD5Ev]+0x13): undefined reference to `vtable for CryptoPP::SimpleKeyingInterface'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::BufferedTransformation::~BufferedTransformation()':
Encryptor.cpp:(.text._ZN8CryptoPP22BufferedTransformationD2Ev[_ZN8CryptoPP22BufferedTransformationD5Ev]+0x13): undefined reference to `vtable for CryptoPP::BufferedTransformation'
Encryptor.cpp:(.text._ZN8CryptoPP22BufferedTransformationD2Ev[_ZN8CryptoPP22BufferedTransformationD5Ev]+0x1f): undefined reference to `vtable for CryptoPP::BufferedTransformation'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::SimpleKeyingInterface::SimpleKeyingInterface()':
Encryptor.cpp:(.text._ZN8CryptoPP21SimpleKeyingInterfaceC2Ev[_ZN8CryptoPP21SimpleKeyingInterfaceC5Ev]+0xf): undefined reference to `vtable for CryptoPP::SimpleKeyingInterface'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::StreamTransformation::~StreamTransformation()':
Encryptor.cpp:(.text._ZN8CryptoPP20StreamTransformationD2Ev[_ZN8CryptoPP20StreamTransformationD5Ev]+0x13): undefined reference to `vtable for CryptoPP::StreamTransformation'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::BlockOrientedCipherModeBase::Resynchronize(unsigned char const*, int)':
Encryptor.cpp:(.text._ZN8CryptoPP27BlockOrientedCipherModeBase13ResynchronizeEPKhi[_ZN8CryptoPP27BlockOrientedCipherModeBase13ResynchronizeEPKhi]+0x23): undefined reference to `CryptoPP::SimpleKeyingInterface::ThrowIfInvalidIVLength(int)'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::Filter::~Filter()':
Encryptor.cpp:(.text._ZN8CryptoPP6FilterD2Ev[_ZN8CryptoPP6FilterD5Ev]+0x13): undefined reference to `vtable for CryptoPP::Filter'
Encryptor.cpp:(.text._ZN8CryptoPP6FilterD2Ev[_ZN8CryptoPP6FilterD5Ev]+0x1f): undefined reference to `vtable for CryptoPP::Filter'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::FilterWithBufferedInput::~FilterWithBufferedInput()':
Encryptor.cpp:(.text._ZN8CryptoPP23FilterWithBufferedInputD2Ev[_ZN8CryptoPP23FilterWithBufferedInputD5Ev]+0x13): undefined reference to `vtable for CryptoPP::FilterWithBufferedInput'
Encryptor.cpp:(.text._ZN8CryptoPP23FilterWithBufferedInputD2Ev[_ZN8CryptoPP23FilterWithBufferedInputD5Ev]+0x1f): undefined reference to `vtable for CryptoPP::FilterWithBufferedInput'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::SecBlock<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, false> >::~SecBlock()':
Encryptor.cpp:(.text._ZN8CryptoPP8SecBlockIhNS_20AllocatorWithCleanupIhLb0EEEED2Ev[_ZN8CryptoPP8SecBlockIhNS_20AllocatorWithCleanupIhLb0EEEED5Ev]+0x27): undefined reference to `CryptoPP::AllocatorWithCleanup<unsigned char, false>::deallocate(void*, unsigned long)'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::SecBlock<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, false> >::New(unsigned long)':
Encryptor.cpp:(.text._ZN8CryptoPP8SecBlockIhNS_20AllocatorWithCleanupIhLb0EEEE3NewEm[_ZN8CryptoPP8SecBlockIhNS_20AllocatorWithCleanupIhLb0EEEE3NewEm]+0x32): undefined reference to `CryptoPP::AllocatorWithCleanup<unsigned char, false>::reallocate(unsigned char*, unsigned long, unsigned long, bool)'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::BlockTransformation::BlockTransformation()':
Encryptor.cpp:(.text._ZN8CryptoPP19BlockTransformationC2Ev[_ZN8CryptoPP19BlockTransformationC5Ev]+0x19): undefined reference to `CryptoPP::Algorithm::Algorithm(bool)'
Encryptor.cpp:(.text._ZN8CryptoPP19BlockTransformationC2Ev[_ZN8CryptoPP19BlockTransformationC5Ev]+0x24): undefined reference to `vtable for CryptoPP::BlockTransformation'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::BlockTransformation::~BlockTransformation()':
Encryptor.cpp:(.text._ZN8CryptoPP19BlockTransformationD2Ev[_ZN8CryptoPP19BlockTransformationD5Ev]+0x13): undefined reference to `vtable for CryptoPP::BlockTransformation'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::Rijndael::Base::Base()':
Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael4BaseC2Ev[_ZN8CryptoPP8Rijndael4BaseC5Ev]+0x20): undefined reference to `vtable for CryptoPP::Rijndael::Base'
Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael4BaseC2Ev[_ZN8CryptoPP8Rijndael4BaseC5Ev]+0x2c): undefined reference to `vtable for CryptoPP::Rijndael::Base'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::Rijndael::Base::~Base()':
Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael4BaseD2Ev[_ZN8CryptoPP8Rijndael4BaseD5Ev]+0x13): undefined reference to `vtable for CryptoPP::Rijndael::Base'
Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael4BaseD2Ev[_ZN8CryptoPP8Rijndael4BaseD5Ev]+0x1f): undefined reference to `vtable for CryptoPP::Rijndael::Base'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::Rijndael::Enc::Enc()':
Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael3EncC2Ev[_ZN8CryptoPP8Rijndael3EncC5Ev]+0x1f): undefined reference to `vtable for CryptoPP::Rijndael::Enc'
Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael3EncC2Ev[_ZN8CryptoPP8Rijndael3EncC5Ev]+0x2b): undefined reference to `vtable for CryptoPP::Rijndael::Enc'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::Rijndael::Enc::~Enc()':
Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael3EncD2Ev[_ZN8CryptoPP8Rijndael3EncD5Ev]+0x13): undefined reference to `vtable for CryptoPP::Rijndael::Enc'
Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael3EncD2Ev[_ZN8CryptoPP8Rijndael3EncD5Ev]+0x1f): undefined reference to `vtable for CryptoPP::Rijndael::Enc'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::BlockCipherFinal<(CryptoPP::CipherDir)0, CryptoPP::Rijndael::Enc>::BlockCipherFinal(unsigned char const*, unsigned long)':
Encryptor.cpp:(.text._ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEC2EPKhm[_ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEC5EPKhm]+0x3b): undefined reference to `CryptoPP::g_nullNameValuePairs'
Encryptor.cpp:(.text._ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEC2EPKhm[_ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEC5EPKhm]+0x4f): undefined reference to `CryptoPP::SimpleKeyingInterface::SetKey(unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&)'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::BlockOrientedCipherModeBase::~BlockOrientedCipherModeBase()':
Encryptor.cpp:(.text._ZN8CryptoPP27BlockOrientedCipherModeBaseD2Ev[_ZN8CryptoPP27BlockOrientedCipherModeBaseD5Ev]+0x13): undefined reference to `vtable for CryptoPP::BlockOrientedCipherModeBase'
Encryptor.cpp:(.text._ZN8CryptoPP27BlockOrientedCipherModeBaseD2Ev[_ZN8CryptoPP27BlockOrientedCipherModeBaseD5Ev]+0x1f): undefined reference to `vtable for CryptoPP::BlockOrientedCipherModeBase'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::CBC_Encryption::~CBC_Encryption()':
Encryptor.cpp:(.text._ZN8CryptoPP14CBC_EncryptionD2Ev[_ZN8CryptoPP14CBC_EncryptionD5Ev]+0x13): undefined reference to `vtable for CryptoPP::CBC_Encryption'
Encryptor.cpp:(.text._ZN8CryptoPP14CBC_EncryptionD2Ev[_ZN8CryptoPP14CBC_EncryptionD5Ev]+0x1f): undefined reference to `vtable for CryptoPP::CBC_Encryption'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::Rijndael::Dec::Dec()':
Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael3DecC2Ev[_ZN8CryptoPP8Rijndael3DecC5Ev]+0x1f): undefined reference to `vtable for CryptoPP::Rijndael::Dec'
Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael3DecC2Ev[_ZN8CryptoPP8Rijndael3DecC5Ev]+0x2b): undefined reference to `vtable for CryptoPP::Rijndael::Dec'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::Rijndael::Dec::~Dec()':
Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael3DecD2Ev[_ZN8CryptoPP8Rijndael3DecD5Ev]+0x13): undefined reference to `vtable for CryptoPP::Rijndael::Dec'
Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael3DecD2Ev[_ZN8CryptoPP8Rijndael3DecD5Ev]+0x1f): undefined reference to `vtable for CryptoPP::Rijndael::Dec'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::BlockCipherFinal<(CryptoPP::CipherDir)1, CryptoPP::Rijndael::Dec>::BlockCipherFinal(unsigned char const*, unsigned long)':
Encryptor.cpp:(.text._ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEC2EPKhm[_ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEC5EPKhm]+0x3b): undefined reference to `CryptoPP::g_nullNameValuePairs'
Encryptor.cpp:(.text._ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEC2EPKhm[_ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEC5EPKhm]+0x4f): undefined reference to `CryptoPP::SimpleKeyingInterface::SetKey(unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&)'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::CBC_Decryption::~CBC_Decryption()':
Encryptor.cpp:(.text._ZN8CryptoPP14CBC_DecryptionD2Ev[_ZN8CryptoPP14CBC_DecryptionD5Ev]+0x13): undefined reference to `vtable for CryptoPP::CBC_Decryption'
Encryptor.cpp:(.text._ZN8CryptoPP14CBC_DecryptionD2Ev[_ZN8CryptoPP14CBC_DecryptionD5Ev]+0x1f): undefined reference to `vtable for CryptoPP::CBC_Decryption'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::AllocatorWithCleanup<unsigned char, true>::allocate(unsigned long, void const*)':
Encryptor.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEmPKv[_ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEmPKv]+0x40): undefined reference to `CryptoPP::AlignedAllocate(unsigned long)'
Encryptor.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEmPKv[_ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEmPKv]+0x4e): undefined reference to `CryptoPP::UnalignedAllocate(unsigned long)'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::AllocatorWithCleanup<unsigned char, true>::deallocate(void*, unsigned long)':
Encryptor.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvm[_ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvm]+0x39): undefined reference to `CryptoPP::AlignedDeallocate(void*)'
Encryptor.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvm[_ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvm]+0x47): undefined reference to `CryptoPP::UnalignedDeallocate(void*)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE]+0x48): undefined reference to `CryptoPP::SimpleKeyingInterface::SetKey(unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE]+0x78): undefined reference to `CryptoPP::SimpleKeyingInterface::GetNextIV(CryptoPP::RandomNumberGenerator&, unsigned char*)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE]+0x88): undefined reference to `CryptoPP::Rijndael::Base::UncheckedSetKey(unsigned char const*, unsigned int, CryptoPP::NameValuePairs const&)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE]+0xa0): undefined reference to `CryptoPP::Rijndael::Dec::ProcessAndXorBlock(unsigned char const*, unsigned char const*, unsigned char*) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE]+0xa8): undefined reference to `CryptoPP::Rijndael::Dec::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE]+0xf0): undefined reference to `non-virtual thunk to CryptoPP::Rijndael::Dec::ProcessAndXorBlock(unsigned char const*, unsigned char const*, unsigned char*) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE]+0x100): undefined reference to `CryptoPP::BlockTransformation::OptimalDataAlignment() const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEE]+0x120): undefined reference to `non-virtual thunk to CryptoPP::Rijndael::Dec::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE]+0x48): undefined reference to `CryptoPP::SimpleKeyingInterface::SetKey(unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE]+0x78): undefined reference to `CryptoPP::SimpleKeyingInterface::GetNextIV(CryptoPP::RandomNumberGenerator&, unsigned char*)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE]+0x88): undefined reference to `CryptoPP::Rijndael::Base::UncheckedSetKey(unsigned char const*, unsigned int, CryptoPP::NameValuePairs const&)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE]+0xa0): undefined reference to `CryptoPP::Rijndael::Dec::ProcessAndXorBlock(unsigned char const*, unsigned char const*, unsigned char*) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE]+0xa8): undefined reference to `CryptoPP::Rijndael::Dec::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE]+0xe8): undefined reference to `non-virtual thunk to CryptoPP::Rijndael::Dec::ProcessAndXorBlock(unsigned char const*, unsigned char const*, unsigned char*) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE]+0xf8): undefined reference to `CryptoPP::BlockTransformation::OptimalDataAlignment() const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEES4_EE]+0x118): undefined reference to `non-virtual thunk to CryptoPP::Rijndael::Dec::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0x48): undefined reference to `CryptoPP::SimpleKeyingInterface::SetKey(unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0x78): undefined reference to `CryptoPP::SimpleKeyingInterface::GetNextIV(CryptoPP::RandomNumberGenerator&, unsigned char*)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0x88): undefined reference to `CryptoPP::Rijndael::Base::UncheckedSetKey(unsigned char const*, unsigned int, CryptoPP::NameValuePairs const&)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0xa0): undefined reference to `CryptoPP::Rijndael::Enc::ProcessAndXorBlock(unsigned char const*, unsigned char const*, unsigned char*) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0xa8): undefined reference to `CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0xf0): undefined reference to `non-virtual thunk to CryptoPP::Rijndael::Enc::ProcessAndXorBlock(unsigned char const*, unsigned char const*, unsigned char*) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0x100): undefined reference to `CryptoPP::BlockTransformation::OptimalDataAlignment() const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0x120): undefined reference to `non-virtual thunk to CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE]+0x48): undefined reference to `CryptoPP::SimpleKeyingInterface::SetKey(unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE]+0x78): undefined reference to `CryptoPP::SimpleKeyingInterface::GetNextIV(CryptoPP::RandomNumberGenerator&, unsigned char*)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE]+0x88): undefined reference to `CryptoPP::Rijndael::Base::UncheckedSetKey(unsigned char const*, unsigned int, CryptoPP::NameValuePairs const&)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE]+0xa0): undefined reference to `CryptoPP::Rijndael::Enc::ProcessAndXorBlock(unsigned char const*, unsigned char const*, unsigned char*) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE]+0xa8): undefined reference to `CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE]+0xe8): undefined reference to `non-virtual thunk to CryptoPP::Rijndael::Enc::ProcessAndXorBlock(unsigned char const*, unsigned char const*, unsigned char*) const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE]+0xf8): undefined reference to `CryptoPP::BlockTransformation::OptimalDataAlignment() const'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE[_ZTVN8CryptoPP12ClonableImplINS_16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEES4_EE]+0x118): undefined reference to `non-virtual thunk to CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const'
   Encryptor.cpp:(.text._ZN8CryptoPP8Rijndael3EncC2ERKS1_[_ZN8CryptoPP8Rijndael3EncC5ERKS1_]+0x36): undefined reference to `vtable for CryptoPP::Rijndael::Enc'
collect2: error: ld returned 1 exit status
cpp/hwinfo/CMakeFiles/hwinfo.dir/build.make:85: recipe for target 'cpp/hwinfo/hwinfo' failed
make[2]: *** [cpp/hwinfo/hwinfo] Error 1
CMakeFiles/Makefile2:167: recipe for target 'cpp/hwinfo/CMakeFiles/hwinfo.dir/all' failed
make[1]: *** [cpp/hwinfo/CMakeFiles/hwinfo.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

我不知道是什么原因造成的。

为什么没有加载我的 Crypto++ 库来解析在我的 Cmake 文件中明确声明的符号?


EDIT:反转库顺序后,如下:

target_link_libraries(hwinfo $LIBCOMMON $LIBCRYPTOPP)

我收到的错误消息越来越少,但仍然是未定义的符号,如下所示:

[71%] Linking CXX executable hwinfo
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::BlockCipherFinal<(CryptoPP::CipherDir)0, CryptoPP::Rijndael::Enc>::BlockCipherFinal(unsigned char const*, unsigned long)':
Encryptor.cpp:(.text._ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEC2EPKhm[_ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEC5EPKhm]+0x3b): undefined reference to `CryptoPP::g_nullNameValuePairs'
../../../lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::BlockCipherFinal<(CryptoPP::CipherDir)1, CryptoPP::Rijndael::Dec>::BlockCipherFinal(unsigned char const*, unsigned long)':
Encryptor.cpp:(.text._ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEC2EPKhm[_ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEC5EPKhm]+0x3b): undefined reference to `CryptoPP::g_nullNameValuePairs'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12CBC_ModeBaseE[_ZTVN8CryptoPP12CBC_ModeBaseE]+0x128): undefined reference to `CryptoPP::StreamTransformation::ProcessLastBlock(unsigned char*, unsigned char const*, unsigned long)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP14CipherModeBaseE[_ZTVN8CryptoPP14CipherModeBaseE]+0x100): undefined reference to `CryptoPP::StreamTransformation::ProcessLastBlock(unsigned char*, unsigned char const*, unsigned long)'
../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP15SymmetricCipherE[_ZTVN8CryptoPP15SymmetricCipherE]+0xe8): undefined reference to `CryptoPP::StreamTransformation::ProcessLastBlock(unsigned char*, unsigned char const*, unsigned long)'
collect2: error: ld returned 1 exit status
cpp/hwinfo/CMakeFiles/hwinfo.dir/build.make:85: recipe for target 'cpp/hwinfo/hwinfo' failed
make[2]: *** [cpp/hwinfo/hwinfo] Error 1
CMakeFiles/Makefile2:167: recipe for target 'cpp/hwinfo/CMakeFiles/hwinfo.dir/all' failed
make[1]: *** [cpp/hwinfo/CMakeFiles/hwinfo.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

【问题讨论】:

另见 GitHub 上的Noloader | Crypto++ Cmake。我们试图支持 Cmake,但它导致了太多问题,因此我们将其分离到一个单独的项目中。 【参考方案1】:

订单很重要!如果库 A 依赖于库 B,则链接时库 A 必须库 B 之前。因此,简单的解决方案是更改链接“通用”库和 cryptopp 库的顺序。

还请注意,由于您显然创建了一个静态库,因此在创建库时您实际上并没有链接任何内容。因此,target_link_libraries 命令对库没有用,因为您的项目当前已设置。

我的建议是将两个CMakeLists.txt 文件链接在一起,因此主可执行文件CMakeLists.txt 使用库CMakeLists.txt 文件(例如使用add_subdirectory 命令)。然后你首先不需要安装库,你可以让COMMON依赖CRYPTOPP,CMake会以正确的顺序链接。

【讨论】:

@SPD,感谢您的帖子,但抱歉,我无法理解您的意思。据我所知,target_link_libraries(hwinfo $LIBCRYPTOPP $LIBCOMMON) 将其按正确的顺序排列,因为 COMMON 取决于 CRYPTOPP。加入这两个 CMakeLists.txt 也无济于事,因为我做不到(这是一个涉及许多 CMakeLists 的更大项目的子集)。如果您发现我的订购有任何错误,请指出...... @Mendes LIBCOMMON 依赖于LIBCRYPTOPP,因此LIBCOMMON 必须是第一个。 交换了位置,但结果没有变化。 target_link_libraries(hwinfo $LIBCOMMON $LIBCRYPTOPP)...同样的错误.... @Mendes 是时候对您的库和可执行文件进行干净且详细的构建了,构建时会启用大量警告。查看正在运行哪些命令来构建您的库和可执行文件。看看您是否可以使用手动构建来复制您的问题,然后尝试使您的手动构建工作。尝试将所有内容最小化,缩小以使其正常工作,然后一次添加一小部分。如果它坏了,那么您就知道问题出在何时何地,并且可以专注于该部分来解决您的问题。 缩小是我所做的。 commoncryptopp 有简单的调用,而hwinfo 是一个调用common 的简单程序......这个问题与链接有关,我真的需要修复我的cmake 文件。检查我的编辑,但反转消息较少,但显示相同的问题。【参考方案2】:

基于此:

我有一个项目依赖于 Debian 8.10 上的 cryptopp

还有这个:

../../../lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP15SymmetricCipherE[_ZTVN8CryptoPP15SymmetricCipherE]+0xe8):
undefined reference to `CryptoPP::StreamTransformation::ProcessLastBlock(unsigned char*, unsigned char const*, unsigned long)'
collect2: error: ld returned 1 exit status

还有这个:

-- CRYPTO LIBRARY ===>/usr/local/lib/libcryptopp.a

看起来您有两个 Crypo++ 库副本,您正在混合和匹配它们。

我认为最简单/最好的解决方法是运行以下命令。他们删除了您的副本,以便您使用 Debian 的副本。

rm -rf /usr/local/include/cryptopp
rm -rf /usr/local/lib/*cryptopp*
rm -rf /usr/local/bin/cryptest*
rm -rf /usr/local/share/cryptopp

我认为这是一个问题的原因是因为ProcessLastBlock 现在返回一个size_t。这种变化发生在 Crypto++ 6.0 上。 OCB 等经过身份验证的加密模式需要进行更改。 OCB 自己处理最后一个块的填充,因此它需要一种方法来指定使用了多少提供的缓冲区。

Crypto++ 5.6.3 和更早的版本使用了ProcessLastBlock,它返回了void。分组密码模式紧密耦合,并且明确要求最后一个块始终是完整的块大小。但就像我说的那样,随着我们开始添加其他操作模式,这并没有成立。

另见filters.cpp中的头注和函数StreamTransformationFilter::LastPut

// This block is new to StreamTransformationFilter. It somewhat of a hack and was added
//  for OCB mode; see GitHub Issue 515. The rub with OCB is, its a block cipher and the
//  last block size can be 0. However, "last block = 0" is not the 0 predacted in the
//  original code. In the orginal code 0 means "nothing special" so DEFAULT_PADDING is
//  applied. OCB's 0 literally means a final block size can be 0 or non-0; and no padding
//  is needed in either case because OCB has its own scheme (see handling of P_* and A_*).
// Stream ciphers have policy objects to convey how to operate the cipher. The Crypto++
//  framework operates well when MinLastBlockSize() is 1. However, it did not appear to
//  cover the OCB case either because we can't stream OCB. It needs full block sizes. In
//  response we hacked a IsLastBlockSpecial(). When true StreamTransformationFilter
//  defers to the mode for processing of the last block.
// The behavior supplied when IsLastBlockSpecial() will likely have to evolve to capture
//  more complex cases from different authenc modes. I suspect it will have to change
//  from a simple bool to something that conveys more information, like "last block
//  no padding" or "custom padding applied by cipher".
// In some respect we have already hit the need for more information. For example, OCB
//  calculates the checksum on the cipher text at the same time, so we don't need the
//  disjoint behavior of calling "EncryptBlock" followed by a separate "AuthenticateBlock".
//  Additional information may allow us to avoid the two spearate calls.

并重申维基上的Linux | Distribution Package:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 8.10 (jessie)
Release:        8.10
Codename:       jessie

$ apt-cache search libcrypto++
...
libcrypto++-dev - General purpose cryptographic library - C++ development
libcrypto++-doc - General purpose cryptographic library - documentation
libcrypto++-utils - General purpose cryptographic library - utilities and data files
libcrypto++9 - General purpose cryptographic library - shared library
libcrypto++9-dbg - General purpose cryptographic library - debug symbols

所以你需要libcrypto++9libcrypto++-dev,可能还有libcrypto++9-dbg

【讨论】:

以上是关于由于未定义的引用,无法链接到 Debian 上的 Crypto++的主要内容,如果未能解决你的问题,请参考以下文章

Raylib 未定义对树莓派上的函数的引用

由于未定义对具有 std::string 的方法的引用,链接 webrtc-native 时出错

由于未定义的引用,无法获取OpenCV进行编译?

使用未定义的引用构建库归档

链接时未定义引用符号'socket@GLIBC_2.4'

我用win7系统,无法获取未定义或null引用的属性“options”