用cryptopp编译程序

问题描述 投票:0回答:1

在generate.cpp里面

...
if (!hash_enabled.empty()) {
            Hash hash;
            std::string hashed_combination = hash.get_hash(combination, hash_enabled);
            hashed_combination = ":" + hashed_combination;
            combination += hashed_combination;
}
...

hash.cpp 里面

#include <cryptopp/md2.h>
#include <cryptopp/md4.h>
#include <cryptopp/md5.h>
#include <cryptopp/sha.h>
#include <cryptopp/sha3.h>
#include <cryptopp/hex.h>
#include <cryptopp/filters.h>
...

std::string get_hash(const std::string& data, const std::string& hash_function) {

    if (hash_function == "md2") {
        Hash::MD MD;
        return MD.MD2(data);
    } else if (hash_function == "md4") {
        Hash::MD MD;
        return MD.MD4(data);
    } else if (hash_function == "md5") {
        Hash::MD MD;
        return MD.MD5(data);
    } else if (hash_function == "sha1-160") {
        Hash::SHA::SHA1 SHA1;
        return SHA1.SHA1_160(data);
    } else if (hash_function == "sha2-224") {
        Hash::SHA::SHA2 SHA2;
        return SHA2.SHA2_224(data);
    } else if (hash_function == "sha2-256") {
        Hash::SHA::SHA2 SHA2;
        return SHA2.SHA2_256(data);
    } else if (hash_function == "sha2-384") {
        Hash::SHA::SHA2 SHA2;
        return SHA2.SHA2_384(data);
    } else if (hash_function == "sha2-512") {
        Hash::SHA::SHA2 SHA2;
        return SHA2.SHA2_512(data);
    } else if (hash_function == "sha3-224") {
        Hash::SHA::SHA3 SHA3;
        return SHA3.SHA3_224(data);
    } else if (hash_function == "sha3-256") {
        Hash::SHA::SHA3 SHA3;
        return SHA3.SHA3_256(data);
    } else if (hash_function == "sha3-384") {
        Hash::SHA::SHA3 SHA3;
        return SHA3.SHA3_384(data);
    } else if (hash_function == "sha3-512") {
        Hash::SHA::SHA3 SHA3;
        return SHA3.SHA3_512(data);
    }

    return "";
}

std::string MD2(const std::string& data) {
    CryptoPP::Weak1::MD2 hash;
    std::string digest;

    CryptoPP::StringSource(data, true,
        new CryptoPP::HashFilter(hash,
            new CryptoPP::HexEncoder(
                new CryptoPP::StringSink(digest)
            )
        )
    );

    return digest;
}

...

仍然出现此错误:

g++ -I"C:\Users\Khakis\AppData\Local\Programs\CLion Nova\bin\mingw\include" -I"C:\msys64\ucrt64\include" .\kplg.cpp .\help.cpp .\get_info.cpp .\generate.cpp .\hash.cpp -o .\khakis.exe -LC:\msys64\ucrt64\include\cryptopp -lcryptopp
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lcryptopp: No such file or directory
collect2.exe: error: ld returned 1 exit status

我错过了什么吗?一些图书馆之类的? 如您所见,编译命令如下所示:

g++ ./kplg.cpp ./help.cpp ./get_info.cpp ./generate.cpp ./hash.cpp -o ./khakis.exe
我不知道

导入了很多东西,修复了 g++ 命令中不包含 hash.cpp 的拼写错误。在互联网上搜索等等

c++ hash compiler-errors
1个回答
0
投票

-L 选项必须指向库文件夹(文件 libcryptopp.so 或 .a 所在的位置) 如果你想包含标题(包含所有 .h 文件的包含文件夹),你必须使用 -I 选项,所以你需要有类似的东西:

-LC:\msys64\ucrt64\{lib64?}\cryptopp -IC:\msys64\ucrt64\include\cryptopp -lcryptopp
© www.soinside.com 2019 - 2024. All rights reserved.