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

时间:2018-06-11 05:53:08

标签: c++ gcc cmake debian crypto++

我有一个依赖于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文件中显式声明的?

编辑 :反转库顺序后,如下:

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

2 个答案:

答案 0 :(得分:1)

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

另请注意,由于您显然创建了静态库,因此在创建库时实际上并未实际链接。因此,target_link_libraries命令对于库来说是无用的,因为您的项目当前已设置好。

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

答案 1 :(得分:0)

基于此:

  

我有一个项目依赖于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的{​​{1}}。块密码模式与显式要求紧密耦合,最后一个块始终为完整块大小。但就像我说的那样,当我们开始增加额外的操作模式时,这并不成立。

另请参阅filters.cpp中的主题提示和void函数:

StreamTransformationFilter::LastPut

并在wiki上重申Linux | Distribution Package

// 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.

因此,您需要$ 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++9以及可能libcrypto++-dev