0

I trying to learn SHA1 on C++ using LibCrypto and I use MSYS2. I already come across some thread on stackoverflow such as Undefined reference to CryptoPP::AlignedAllocate(unsigned int) but still I can't build the code. It's a simple code that's written on the Crypto++ Wiki https://www.cryptopp.com/wiki/SHA, I tried

#include "cryptlib.h"
#include "sha.h"
#include <iostream>

int main (int argc, char* argv[])
{
    using namespace CryptoPP;

    SHA1 hash;  
    std::cout << "Name: " << hash.AlgorithmName() << std::endl;
    std::cout << "Digest size: " << hash.DigestSize() << std::endl;
    std::cout << "Block size: " << hash.BlockSize() << std::endl;

    return 0; 
}

But end up with some many error

Ben@BEN-ASUS-A43SV MSYS /d/Users/Ben/My Desktop/crypto
$ g++ main.cpp -o main.exe -I . -lpthread
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.text$_ZN8CryptoPP18HashTransformationC2Ev[_ZN8CryptoPP18HashTransformationC2Ev]+0x19): undefined reference to `CryptoPP::Algorithm::Algorithm(bool)'
/tmp/ccYhY8rM.o:main.cpp:(.text$_ZN8CryptoPP18HashTransformationC2Ev[_ZN8CryptoPP18HashTransformationC2Ev]+0x19): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `CryptoPP::Algorithm::Algorithm(bool)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.text$_ZN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EE4InitEv[_ZN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EE4InitEv]+0x20): undefined reference to `CryptoPP::SHA1::InitState(unsigned int*)'
/tmp/ccYhY8rM.o:main.cpp:(.text$_ZN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EE4InitEv[_ZN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EE4InitEv]+0x20): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `CryptoPP::SHA1::InitState(unsigned int*)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EEE[_ZTVN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EEE]+0x38): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::Update(unsigned char const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EEE[_ZTVN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EEE]+0x40): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::CreateUpdateSpace(unsigned long&)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EEE[_ZTVN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EEE]+0x50): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::Restart()'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EEE[_ZTVN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EEE]+0x90): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::TruncatedFinal(unsigned char*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EEE[_ZTVN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EEE]+0xa0): undefined reference to `CryptoPP::HashTransformation::TruncatedVerify(unsigned char const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EEE[_ZTVN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EEE]+0xc8): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::HashMultipleBlocks(unsigned int const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP12ClonableImplINS_4SHA1ENS_13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEES1_EEEE[_ZTVN8CryptoPP12ClonableImplINS_4SHA1ENS_13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEES1_EEEE]+0x38): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::Update(unsigned char const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP12ClonableImplINS_4SHA1ENS_13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEES1_EEEE[_ZTVN8CryptoPP12ClonableImplINS_4SHA1ENS_13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEES1_EEEE]+0x40): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::CreateUpdateSpace(unsigned long&)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP12ClonableImplINS_4SHA1ENS_13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEES1_EEEE[_ZTVN8CryptoPP12ClonableImplINS_4SHA1ENS_13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEES1_EEEE]+0x50): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::Restart()'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP12ClonableImplINS_4SHA1ENS_13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEES1_EEEE[_ZTVN8CryptoPP12ClonableImplINS_4SHA1ENS_13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEES1_EEEE]+0x90): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::TruncatedFinal(unsigned char*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP12ClonableImplINS_4SHA1ENS_13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEES1_EEEE[_ZTVN8CryptoPP12ClonableImplINS_4SHA1ENS_13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEES1_EEEE]+0xa0): undefined reference to `CryptoPP::HashTransformation::TruncatedVerify(unsigned char const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP12ClonableImplINS_4SHA1ENS_13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEES1_EEEE[_ZTVN8CryptoPP12ClonableImplINS_4SHA1ENS_13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEES1_EEEE]+0xc8): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::HashMultipleBlocks(unsigned int const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEENS_4SHA1EEE[_ZTVN8CryptoPP13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEENS_4SHA1EEE]+0x38): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::Update(unsigned char const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEENS_4SHA1EEE[_ZTVN8CryptoPP13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEENS_4SHA1EEE]+0x40): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::CreateUpdateSpace(unsigned long&)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEENS_4SHA1EEE[_ZTVN8CryptoPP13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEENS_4SHA1EEE]+0x50): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::Restart()'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEENS_4SHA1EEE[_ZTVN8CryptoPP13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEENS_4SHA1EEE]+0x90): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::TruncatedFinal(unsigned char*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEENS_4SHA1EEE[_ZTVN8CryptoPP13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEENS_4SHA1EEE]+0xa0): undefined reference to `CryptoPP::HashTransformation::TruncatedVerify(unsigned char const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEENS_4SHA1EEE[_ZTVN8CryptoPP13AlgorithmImplINS_12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEENS_4SHA1EEE]+0xc8): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::HashMultipleBlocks(unsigned int const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEE[_ZTVN8CryptoPP12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEE]+0x38): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::Update(unsigned char const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEE[_ZTVN8CryptoPP12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEE]+0x40): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::CreateUpdateSpace(unsigned long&)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEE[_ZTVN8CryptoPP12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEE]+0x50): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::Restart()'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEE[_ZTVN8CryptoPP12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEE]+0x90): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::TruncatedFinal(unsigned char*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEE[_ZTVN8CryptoPP12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEE]+0xa0): undefined reference to `CryptoPP::HashTransformation::TruncatedVerify(unsigned char const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEE[_ZTVN8CryptoPP12IteratedHashIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ENS_18HashTransformationEEE]+0xc8): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::HashMultipleBlocks(unsigned int const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP16IteratedHashBaseIjNS_18HashTransformationEEE[_ZTVN8CryptoPP16IteratedHashBaseIjNS_18HashTransformationEEE]+0x38): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::Update(unsigned char const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP16IteratedHashBaseIjNS_18HashTransformationEEE[_ZTVN8CryptoPP16IteratedHashBaseIjNS_18HashTransformationEEE]+0x40): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::CreateUpdateSpace(unsigned long&)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP16IteratedHashBaseIjNS_18HashTransformationEEE[_ZTVN8CryptoPP16IteratedHashBaseIjNS_18HashTransformationEEE]+0x50): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::Restart()'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP16IteratedHashBaseIjNS_18HashTransformationEEE[_ZTVN8CryptoPP16IteratedHashBaseIjNS_18HashTransformationEEE]+0x90): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::TruncatedFinal(unsigned char*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP16IteratedHashBaseIjNS_18HashTransformationEEE[_ZTVN8CryptoPP16IteratedHashBaseIjNS_18HashTransformationEEE]+0xa0): undefined reference to `CryptoPP::HashTransformation::TruncatedVerify(unsigned char const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$_ZTVN8CryptoPP16IteratedHashBaseIjNS_18HashTransformationEEE[_ZTVN8CryptoPP16IteratedHashBaseIjNS_18HashTransformationEEE]+0xc8): undefined reference to `CryptoPP::IteratedHashBase<unsigned int, CryptoPP::HashTransformation>::HashMultipleBlocks(unsigned int const*, unsigned long)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.text$_ZN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EE24HashEndianCorrectedBlockEPKj[_ZN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EE24HashEndianCorrectedBlockEPKj]+0x2b): undefined reference to `CryptoPP::SHA1::Transform(unsigned int*, unsigned int const*)'
/tmp/ccYhY8rM.o:main.cpp:(.text$_ZN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EE24HashEndianCorrectedBlockEPKj[_ZN8CryptoPP31IteratedHashWithStaticTransformIjNS_10EnumToTypeINS_9ByteOrderELi1EEELj64ELj20ENS_4SHA1ELj0ELb0EE24HashEndianCorrectedBlockEPKj]+0x2b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `CryptoPP::SHA1::Transform(unsigned int*, unsigned int const*)'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$.refptr._ZTVN8CryptoPP4SHA1E[.refptr._ZTVN8CryptoPP4SHA1E]+0x0): undefined reference to `vtable for CryptoPP::SHA1'
/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/ccYhY8rM.o:main.cpp:(.rdata$.refptr._ZTVN8CryptoPP18HashTransformationE[.refptr._ZTVN8CryptoPP18HashTransformationE]+0x0): undefined reference to `vtable for CryptoPP::HashTransformation'
collect2: error: ld returned 1 exit status

I'm Quite confused because first I tried using https://packages.msys2.org/package/mingw-w64-x86_64-crypto++ package on msys2, but still not working, 2nd attempt I tried using source code from LibCrypto website.

Any help is appriciated. Thank you

2nd attempt I did is using -lcrypto flag but no luck. Anyway I tried it with fedora with g++ -DNDEBUG -g3 -O2 -Wall -Wextra -o test main.cpp -L/usr/lib64 -lcryptopp and it works perfectly. I really want to know what cause this not working. hmm.. on MSYS I already install libcryptopp.a. hmm..

Benyamin Limanto
  • 775
  • 10
  • 24
  • 1
    This is your command `g++ main.cpp -o main.exe -I . -lpthread`? You don't seem to be linking with the libcrypto library. – john Jun 29 '20 at 06:19
  • At the very least you need to add `-lcrypto` near the end of your build command (not exactly sure where). Try `g++ main.cpp -o main.exe -I . -lcrypto -lpthread` – john Jun 29 '20 at 06:24
  • @john I tried, and it's still not working on MSYS, and I really wanted to know why. Anyway the LINK that's set above that said it's answered there isn't the answer for this problem. I tried on Fedora with `g++ -DNDEBUG -g3 -O2 -Wall -Wextra -o test main.cpp -L/usr/lib64 -lcryptopp` works But not on windows, I mean I tried `g++ -DNDEBUG -g3 -O2 -Wall -Wextra -o test main.cpp -L/mingw64/lib -lcryptopp` and `g++ -DNDEBUG -g3 -O2 -Wall -Wextra -o test main.cpp -l:libcryptopp.a` still not solving the problem and set not found. but on Fedora it works. – Benyamin Limanto Jun 29 '20 at 07:05
  • If you are getting `not found` error message and you do have the library built, then that just means you aren't setting the library search path correctly (`-L` option). – john Jun 29 '20 at 07:08
  • @john nah It should be, but I already set it using `-L/mingw64/lib` and it the .a lib is reside at /mingw64/lib/libcryptopp.a – Benyamin Limanto Jun 29 '20 at 07:10
  • Could it be a 32 bit vs 64 bit issue? I think if you are building a 32 bit application then any 64 bit libraries get ignored. – john Jun 29 '20 at 07:15
  • @john How to know that? I mean how to trace that, because it's just simple code from the wiki, see https://www.cryptopp.com/wiki/SHA, it shouldn't have any problem with 32 or 64 I think. – Benyamin Limanto Jun 29 '20 at 07:16
  • Your library is (apparently) 64 bit because `-L/mingw64/lib`. The command `gcc -v` will tell you whether you have a 32 bit or 64 bit compiler. I'm just guessing here, don't imagine I know what I'm talking about. – john Jun 29 '20 at 07:24
  • Looking at the output above it seems you do have a 64 bit compiler. – john Jun 29 '20 at 07:24
  • @john I already ask msys2 guys, and I use the wrong g++, so the g++ that I've isn't the one who have the lib. But seems some of your statement are true. – Benyamin Limanto Jun 29 '20 at 08:44

0 Answers0