【问题标题】:2 Errors when trying to compile the bcrypt project2 尝试编译 bcrypt 项目时出错
【发布时间】:2019-10-12 04:56:24
【问题描述】:

我正在使用 bcrypt 库并收到以下错误:

错误 LNK2019 未解析的外部符号 bcrypt_gensalt 在函数“public: static class std::basic_string,class std::allocator > cdecl BCrypt::generateHash(class std::basic_string,class std::allocator > const &,int )" (?generateHash@BCrypt@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV23@H@Z)

错误 LNK2019 未解析的外部符号 bcrypt_hashpw 在函数“public: static class std::basic_string,class std::allocator > cdecl BCrypt::generateHash(class std::basic_string,class std::allocator > const &,int )" (?generateHash@BCrypt@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV23@H@Z)

这是我的测试代码:

#include <iostream>
#include "bcrypt/BCrypt.hpp"

BCrypt bcrypt;

using namespace std;

int main() {
    string password = "test";
    string hash = bcrypt.generateHash(password);
    cout << bcrypt.validatePassword(password, hash) << endl;
    cout << bcrypt.validatePassword("test1", hash) << endl;
}

【问题讨论】:

  • 这个错误意味着函数bcrypt_gensalt(和bcrypt_hashpw)被声明在某处,以便编译器可以生成调用,但是链接器在将编译的目标文件汇编成一个可执行文件。可能,您正在尝试使用非仅包含标头的库而不编译它或指示链接器使用它。显示用于编译和链接代码的命令。

标签: c++ unresolved-external


【解决方案1】:

我用过这段代码

#include <iostream>
#include "bcrypt/BCrypt.hpp"

BCrypt bcrypt;

using namespace std;

int main() {

    string password = "test";
    string hash = bcrypt.generateHash(password);
    cout << bcrypt.validatePassword(password, hash) << endl;
    cout << bcrypt.validatePassword("test1", hash) << endl;

}

【讨论】:

猜你喜欢
  • 2013-03-04
  • 1970-01-01
  • 2018-12-10
  • 1970-01-01
  • 2014-09-12
  • 2018-07-14
  • 2016-09-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多