0

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;
}
Evg
  • 25,259
  • 5
  • 41
  • 83
  • 2
    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 May 26 '19 at 09:25
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – melpomene May 26 '19 at 09:45

1 Answers1

0

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;

}
  • You should compile the library (or use pre-compiled binaries) and link your code againt it. Just including `bcrypt/BCrypt.hpp` is not enough. See: https://stackoverflow.com/questions/23177550/what-does-it-mean-to-link-against-something – Evg May 26 '19 at 10:14