我下载了一个 cryptopp 8.7.0 并尝试在
VSCode
中编译它。
编译参数:
A:\msys64\mingw64\bin\g++.exe -g A:\folder\AES256_GSM_C++\test.cpp -static -static-libgcc -static-libstdc++ -lcrypto++ -o A:\Andrey_dev\AES256_GSM_C++\test.exe
如果我尝试编译我的代码,我会得到以下错误:
a:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lcrypto++: No such file or directory
(注意:与
-lcryptopp
相同的错误,没有目录)
代码:
#include "cryptopp/cryptlib.h"
#include "cryptopp/rijndael.h"
#include "cryptopp/modes.h"
#include "cryptopp/files.h"
#include "cryptopp/osrng.h"
#include "cryptopp/hex.h"
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int main(int argc, char *argv[])
{
using namespace CryptoPP;
AutoSeededRandomPool prng;
HexEncoder encoder(new FileSink(std::cout));
SecByteBlock key(AES::DEFAULT_KEYLENGTH);
SecByteBlock iv(AES::BLOCKSIZE);
prng.GenerateBlock(key, key.size());
prng.GenerateBlock(iv, iv.size());
std::string plain = "CBC Mode Test";
std::string cipher, recovered;
std::cout << "plain text: " << plain << std::endl;
/*********************************\
\*********************************/
try
{
CBC_Mode<AES>::Encryption e;
e.SetKeyWithIV(key, key.size(), iv);
StringSource s(plain, true,
new StreamTransformationFilter(e,
new StringSink(cipher)) // StreamTransformationFilter
); // StringSource
}
catch (const Exception &e)
{
std::cerr << e.what() << std::endl;
exit(1);
}
/*********************************\
\*********************************/
std::cout << "key: ";
encoder.Put(key, key.size());
encoder.MessageEnd();
std::cout << std::endl;
std::cout << "iv: ";
encoder.Put(iv, iv.size());
encoder.MessageEnd();
std::cout << std::endl;
std::cout << "cipher text: ";
encoder.Put((const BYTE *)&cipher[0], cipher.size());
encoder.MessageEnd();
std::cout << std::endl;
/*********************************\
\*********************************/
try
{
CBC_Mode<AES>::Decryption d;
d.SetKeyWithIV(key, key.size(), iv);
StringSource s(cipher, true,
new StreamTransformationFilter(d,
new StringSink(recovered)) // StreamTransformationFilter
); // StringSource
std::cout << "recovered text: " << recovered << std::endl;
}
catch (const Exception &e)
{
std::cerr << e.what() << std::endl;
exit(1);
}
return 0;
}
此外,我尝试在
-L ${fileDirname}\\cryptopp
中使用 write tasks.json
,我得到了许多未定义的引用:
$_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0xb8): undefined reference to `CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long long, unsigned int) const'
a:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccNDcpyR.o:test.cpp:(.rdata$_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0x100): undefined reference to `non-virtual thunk to CryptoPP::Rijndael::Base::AlgorithmProvider[abi:cxx11]() const'
a:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccNDcpyR.o:test.cpp:(.rdata$_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0x108): undefined reference to `non-virtual thunk to CryptoPP::Rijndael::Enc::ProcessAndXorBlock(unsigned char const*, unsigned char const*, unsigned char*) const'
a:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccNDcpyR.o:test.cpp:(.rdata$_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0x118): undefined reference to `non-virtual thunk to CryptoPP::Rijndael::Base::OptimalDataAlignment() const'
a:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccNDcpyR.o:test.cpp:(.rdata$_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE[_ZTVN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEE]+0x138): undefined reference to `non-virtual thunk to CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long long, unsigned int) const'
我没有显示所有错误,实际上还有更多。
有什么想法吗?
编辑:当我使用
cryptopp
安装MSYS2
时,大多数问题都消失了,但在libcryptopp.a
中出现了未定义引用的另一个问题
错误:
a:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: a:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../lib\libcryptopp.a(files.cpp.obj):(.text+0x9a): undefined reference to std::istream::seekg(std::fpos<int>)'