2012-07-17 60 views
0
#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; 
} 

錯誤無法編譯加密的SHA-256散列上DEVC

編譯:默認的編譯器 執行G ++的exe ... G ++ exe文件「C:\用戶\鐠\桌面\工作\加密\ sha256 \ sampeSHA256.cpp「-o」C:\ Users \ Pr \ Desktop \ Work \ encrypt \ sha256 \ sampeSHA256.exe「-I」C:\ Dev-Cpp \ lib \ gcc \ mingw32 \ 3.4.2 \包括「-I」C:\ Dev-Cpp \ include \ C++ \ 3.4.2 \ backward「-I」C:\ Dev-Cpp \ include \ C++ \ 3.4.2 \ mingw32「-I」C:\ Dev- C++ \ 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, from C:/ Dev-Cpp/include/C++/3.4.2/back病房/ .. \ cryptopp/rijndael.h:7, 從C:/開發-CPP /包括/ C++/3.4.2 /向後/ .. \ cryptopp/aes.h:4, 從C:/ DEV- CPP /包括/ C++/3.4.2 /向後/ .. \ cryptopp \ dll.h:11, 從C:\用戶\鐠\桌面\工作\加密\ SHA256 \ sampeSHA256.cpp:1: C:/開發-CPP /包括/ C++/3.4.2 /向後/ .. \ 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: function布爾cryptoPP :: namevaluepairs中:: GetIntValue(常量字符*,詮釋&)const的」定義被標記dllimport的。 C:/開發-CPP /包括/ C++/3.4.2 /向後/ .. \ 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: function靜態無效CryptoPP :: namevaluepairs中:: ThrowIfTypeMismatch(常量字符*,常量性病: :type_info &,const std :: type_info &)'的定義被標記爲dllimport。 C:/ Dev-Cpp/include/C++/3.4.2/backward/.. \ cryptopp/cryptlib.h:301:error:function`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 0.2 /後退/ .. \ cryptopp \ dll.h:11, 從C:\用戶\鐠\桌面\工作\加密\ SHA256 \ sampeSHA256.cpp:1: C:/開發-CPP /包括/ C++ /3.4.2/backward/..\cryptopp/rijndael.h:15:錯誤:函數`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。我們可以通過下面的例子來說明如何使用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。

執行終止

+0

你可以發佈你用來編譯你的程序的命令嗎? – Fraser 2012-07-18 22:14:59

+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「 – user1532707 2012-07-19 18:13:45

+0

你沒有鏈接到cryptopp庫,你有嗎?命令中不應該有'-lcryptopp'嗎? – Fraser 2012-07-19 23:35:15

回答

0

刪除#include <..\cryptopp\dll.h>

正如弗雷澤說,使用-L<path to Crypto++>

正如弗雷澤說,使用-lcryptopp-lcrypto++。你使用的取決於你有什麼。默認情況下,其-lcryptopp