1

I'm trying to run this example utilizing Crypto++library, and I downloaded/stored Crypto++ in /home/thirdparty/cryptopp. However, when run the following command line:

g++ -I/home/thirdParty channelSwitch.cpp -L/home/thirParty -o test-cs.exe

Can someone help check what is the problem?

/tmp/ccPnCG56.o: In function `main':
channelSwitch.cpp:(.text+0x178): undefined reference to `CryptoPP::StringSinkTemplate<std::string>::StringSinkTemplate(std::string&)'
channelSwitch.cpp:(.text+0x21b): undefined reference to `CryptoPP::DEFAULT_CHANNEL'
channelSwitch.cpp:(.text+0x221): undefined reference to `CryptoPP::DEFAULT_CHANNEL'
channelSwitch.cpp:(.text+0x237): undefined reference to `CryptoPP::HashFilter::HashFilter(CryptoPP::HashTransformation&, CryptoPP::BufferedTransformation*, bool, int, std::string const&, std::string const&)'
channelSwitch.cpp:(.text+0x292): undefined reference to `CryptoPP::StringSinkTemplate<std::string>::StringSinkTemplate(std::string&)'
channelSwitch.cpp:(.text+0x31d): undefined reference to `CryptoPP::DEFAULT_CHANNEL'
channelSwitch.cpp:(.text+0x323): undefined reference to `CryptoPP::DEFAULT_CHANNEL'
channelSwitch.cpp:(.text+0x339): undefined reference to `CryptoPP::HashFilter::HashFilter(CryptoPP::HashTransformation&, CryptoPP::BufferedTransformation*, bool, int, std::string const&, std::string const&)'
...
collect2: error: ld returned 1 exit status

The complete source code for channelSwitch.cpp is:

#include <iostream>
#include <cstring>
#include <cryptopp/channels.h> 
#include <cryptopp/filters.h> 
#include <cryptopp/sha.h> 
#include <cryptopp/hex.h>

int main(int argc, char *argv[]) {
std::string message = "Now is the time for all good men to come to the aide of their country";

// Allow user to override default message from command line arg.
if(argc == 2 && argv[1] != NULL) 
    message = std::string(argv[1]);

// Set hash variables
std::string s1, s2, s3, s4;
CryptoPP::SHA1 sha1; CryptoPP::SHA224 sha224; CryptoPP::SHA256 sha256; CryptoPP::SHA512 sha512;

// Run hash functions
CryptoPP::HashFilter f1(sha1, new CryptoPP::HexEncoder(new CryptoPP::StringSink(s1)));
CryptoPP::HashFilter f2(sha224, new CryptoPP::HexEncoder(new CryptoPP::StringSink(s2)));
CryptoPP::HashFilter f3(sha256, new CryptoPP::HexEncoder(new CryptoPP::StringSink(s3)));
CryptoPP::HashFilter f4(sha512, new CryptoPP::HexEncoder(new CryptoPP::StringSink(s4)));

// Set route to default
CryptoPP::ChannelSwitch cs;
cs.AddDefaultRoute(f1);
cs.AddDefaultRoute(f2);
cs.AddDefaultRoute(f3);
cs.AddDefaultRoute(f4);

CryptoPP::StringSource ss(message, true /*pumpAll*/, new CryptoPP::Redirector(cs));

std::cout << "Message: " << message << std::endl;
std::cout << "SHA-1: " << s1 << std::endl;
std::cout << "SHA-224: " << s2 << std::endl;
std::cout << "SHA-256: " << s3 << std::endl;
std::cout << "SHA-512: " << s4 << std::endl;
return 0;
}

Environment information:

$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
jww
  • 97,681
  • 90
  • 411
  • 885
Sarah
  • 453
  • 7
  • 16
  • 2
    You are not linking cryptopp. – tkausl Mar 28 '18 at 18:28
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Mike Kinghan Mar 30 '18 at 07:12

1 Answers1

0

I know what the problem is. should make install first. Thanks!

Sarah
  • 453
  • 7
  • 16
  • You should also consider using [Crypto++ 6.1](https://www.cryptopp.com/index.html). How did you come to downloading 5.6.5? – jww Mar 29 '18 at 05:19