Reputation: 662
I am using this bcrypt library for some password hashing. I have used the provided makefile to generate a library file called bcrypt.a. I also have the header file in my code and I using a class (Cryto.h/Crypto.cpp) to create a wrapper around the header functions. I am trying to compile my code with with the .a library file by doing:
g++ -std=c++14 -o geemail auth/auth.cpp services/services.cpp crypto/crypto.cpp database/database.cpp main.cpp libraries/bcrypt/bcrypt.a -lsqlite3 -lsodium
I have included my header file (bcrypt.h) that has the correct function definitions in my crypto.h file. But I keep getting this error when I run the command above.
/tmp/ccM1cHRo.o: In function `Crypto::CompareHash(char const*, char const*)':
crypto.cpp:(.text+0x23): undefined reference to `bcrypt_checkpw'
/tmp/ccM1cHRo.o: In function `Crypto::GetGeneratedHash[abi:cxx11](char
const*, char*, char*)':
crypto.cpp:(.text+0x63): undefined reference to `bcrypt_gensalt'
crypto.cpp:(.text+0x7a): undefined reference to `bcrypt_hashpw'
collect2: error: ld returned 1 exit status
Looks like its unable to find any of the functions declared in the bcrypt.h file even though the header is included properly. What is the proper way of linking these files?
Upvotes: 0
Views: 341
Reputation: 949
Try this:
g++ -std=c++14 -o geemail auth/auth.cpp services/services.cpp crypto/crypto.cpp database/database.cpp main.cpp -Llibraries/bcrypt -lbcrypt -lsqlite3 -lsodium
Upvotes: 1