【发布时间】: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)被声明在某处,以便编译器可以生成调用,但是链接器在将编译的目标文件汇编成一个可执行文件。可能,您正在尝试使用非仅包含标头的库而不编译它或指示链接器使用它。显示用于编译和链接代码的命令。