So I am trying to make a wrapper function for generating a hash using Cryptop++ I created this test function:
#include <cryptopp/sha.h>
#include <cryptopp/hex.h>
#include <cryptopp/cryptlib.h>
#include <vector>
#include <cstdint>
#include <string>
#include <iostream>
void test2()
{
CryptoPP::SHA1 hash;
CryptoPP::byte digest[CryptoPP::SHA1::DIGESTSIZE];
std::vector<uint8_t> v;
for (uint32_t i = 0; i < 1000; ++i)
{
v.push_back(i % 9);
}
hash.CalculateDigest(digest, v.data(), v.size());
CryptoPP::HexEncoder encoder;
std::string output;
encoder.Attach(new CryptoPP::StringSink(output));
encoder.Put(digest, sizeof(digest));
encoder.MessageEnd();
std::cout << output << std::endl;
}
And compiled it with the following clang++ string: clang++ main2.cpp -lcryptopp
. However, when I use it in my project where the function is defined like this:
template<typename Hash>
std::string get_hash(std::vector<uint8_t> data)
{
Hash hash;
// Intialise a byte "array" with space enough for the result
CryptoPP::byte digest[Hash::DIGESTSIZE];
// Create hash for the data
hash.CalculateDigest(digest, data.data(), data.size());
CryptoPP::HexEncoder encoder;
// result will hold the hex representation of the hash
std::string result;
// Tell the Hex encoder that result is the destination
// for its operations
encoder.Attach(new CryptoPP::StringSink(result));
encoder.Put(digest, sizeof(digest));
// As we will not put more in the message we end it
encoder.MessageEnd();
return result;
}
And call it like this: hash::get_hash<CryptoPP::SHA1>(pair.pivot);
with following compiler command: clang++ -std=c++17 -Wall -Werror -Wextra -pthread -pthread -lpqxx -lpq -lcryptopp examples/sql_index_example/sql_index_example.cpp.1.o -o/home/tools/git/alexandria/build/examples/sql_index_example/sql_index_example -Wl-Bstatic -L. -lalexandria -Wl-Bdynamic
I get a ton of undefined references to Crypto++, such as:
examples/sql_index_example/sql_index_example.cpp.1.o: In function `alexandria::data::hash::GetHash[abi:cxx11](std::vector<unsigned char, std::allocator<unsigned char> >)':
sql_index_example.cpp:(.text+0x197): undefined reference to `CryptoPP::StringSinkTemplate<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::StringSinkTemplate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
and I am quite lost as to what actually happens when the simple test works. So hope someone can help.
EDIT: Already tried: Undefined reference to symbol, even though the library is linked