0
votes

I'm using bcrypt library and getting these errors:

Error LNK2019 unresolved external symbol bcrypt_gensalt referenced in function "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)

Error LNK2019 unresolved external symbol bcrypt_hashpw referenced in function "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)

Here's my test code:

#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;
}
1
This error means that the function bcrypt_gensalt (and bcrypt_hashpw) is declared somewhere so that the compiler can generate a call, but the linker cannot find its definition when it assembles the compiled object files into an executable. Probably, you're trying to use a non-header-only library without compiling it or instructing the linker to use it. Show the commands you use to compile and link your code.Evg

1 Answers

0
votes

I used this code

#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;

}