【问题标题】:Unable to compile crypto for SHA-256 hashing on Devc无法在 Devc 上为 SHA-256 哈希编译加密
【发布时间】:2012-07-16 18:08:03
【问题描述】:
#include <..\cryptopp\dll.h>
#include <..\cryptopp\sha.h>
#include <..\cryptopp\hex.h>
#include<..\cryptopp\files.h>

#include <iostream>
#include<string>

using namespace std;
using namespace CryptoPP;

const int MAX_PHRASE_LENGTH=250;

int main(int argc, char *argv[]) {

CryptoPP::SHA256 hash;
byte digest[ CryptoPP::SHA256::DIGESTSIZE ];
std::string message = "Hello World!";

hash.CalculateDigest( digest, (const byte*)message.c_str(), message.length());

CryptoPP::HexEncoder encoder;
std::string output;
encoder.Attach( new CryptoPP::StringSink( output ) );
encoder.Put( digest, sizeof(digest) );
encoder.MessageEnd();

std::cout << "Input string: " << message << std::endl;
std::cout << "SHA256: " << output << std::endl;

return 0;
}

错误

编译器:默认编译器 正在执行 g++.exe... g++.exe "C:\Users\Pr\Desktop\Work\encrypt\sha256\sampeSHA256.cpp" -o "C:\Users\Pr\Desktop\Work\encrypt\sha256\sampeSHA256.exe" -I"C: \Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++ \3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" 在 C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp/seckey.h:8 包含的文件中, 来自 C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp/rijndael.h:7, 来自 C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp/aes.h:4, 来自 C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp\dll.h:11, 从 C:\Users\Pr\Desktop\Work\encrypt\sha256\sampeSHA256.cpp:1: C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp/cryptlib.h:277: 错误:函数std::string CryptoPP::NameValuePairs::GetValueNames() const' definition is marked dllimport. C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp\/cryptlib.h:283: error: functionbool CryptoPP::NameValuePairs::GetIntValue(const char*, int&) const ' 定义标记为 dllimport。 C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp/cryptlib.h:287: 错误:函数int CryptoPP::NameValuePairs::GetIntValueWithDefault(const char*, int) const' definition is marked dllimport. C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp\/cryptlib.h:291: error: functionstatic void CryptoPP::NameValuePairs::ThrowIfTypeMismatch(const char*, const std ::type_info&, const std::type_info&)' 定义标记为 dllimport。 C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp/cryptlib.h:301: 错误: 函数`void CryptoPP::NameValuePairs::GetRequiredIntParameter(const char*, const char*, int& ) const' 定义标记为 dllimport。

在 C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp/aes.h:4 包含的文件中, 来自 C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp\dll.h:11, 从 C:\Users\Pr\Desktop\Work\encrypt\sha256\sampeSHA256.cpp:1: C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp/rijndael.h:15: 错误: function `static const char* CryptoPP::Rijndael_Info::StaticAlgorithmName()' 定义标记为 dllimport .

在 C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp\dll.h:16 包含的文件中, 从 C:\Users\Pr\Desktop\Work\encrypt\sha256\sampeSHA256.cpp:1: C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp/des.h:58: error: function `static const char* CryptoPP::DES_EDE2_Info::StaticAlgorithmName()' 定义标记为 dllimport .

C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp/des.h:82: 错误:函数 `static const char* CryptoPP::DES_EDE3_Info::StaticAlgorithmName()' 定义标记为 dllimport。

在 C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp\dll.h:37 包含的文件中, 从 C:\Users\Pr\Desktop\Work\encrypt\sha256\sampeSHA256.cpp:1: C:/Dev-Cpp/include/c++/3.4.2/backward/..\cryptopp/skipjack.h:15: error: function `static const char* CryptoPP::SKIPJACK_Info::StaticAlgorithmName()' 定义标记为 dllimport .

执行终止

【问题讨论】:

  • 你能发布你用来编译你的程序的命令吗?
  • 正在执行 g++.exe... g++.exe "C:\Users\Pr\Desktop\Work\encrypt\sha256\sampeSHA256.cpp" -o "C:\Users\Pr\Desktop\ Work\encrypt\sha256\sampeSHA256.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\向后" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\包括"-L"C:\Dev-Cpp\lib"
  • 你没有链接到 cryptopp 库,是吗?命令中不应该有-lcryptopp吗?
  • 它说 -lcryptopp 未找到,我应该将它指向特定的目标文件或文件夹吗?
  • -lcryptopp 告诉 g++ 链接到 CryptoPP 库。它可以被称为libcryptopp.acryptopp.so - 我不确定 - 我不在 Windows 上使用 g++。我认为您已经构建了 CryptoPP?如果是这样,只需找到库并将目录的路径作为-L 标志传递(就像你已经得到-L"C:\Dev-Cpp\lib" 一样。我认为pthread 也是一个依赖项,你可能还需要将-lpthread 添加到你的命令。

标签: dev-c++ crypto++


【解决方案1】:

删除#include &lt;..\cryptopp\dll.h&gt;

正如弗雷泽所说,使用-L&lt;path to Crypto++&gt;

正如弗雷泽所说,使用-lcryptopp-lcrypto++。您使用的取决于您所拥有的。默认为-lcryptopp

【讨论】:

    猜你喜欢
    • 2014-08-19
    • 2023-03-18
    • 2013-01-09
    • 2017-09-20
    • 2012-01-08
    • 2015-08-21
    • 2021-11-25
    • 2012-09-12
    • 1970-01-01
    相关资源
    最近更新 更多