0

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?

Dikshant Adhikari
  • 664
  • 1
  • 10
  • 24
  • note how you prepended the other libraries (sqlite3, sodium) with `-l` – user4581301 Nov 12 '17 at 23:04
  • @user4581301I have tried it that way too I get the same error. I was just explicitly providing the path in this case. Oddly enough it works fine on MacOS but not in Ubuntu 17.04 using gcc 7 – Dikshant Adhikari Nov 12 '17 at 23:07

1 Answers1

1

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
Eyal Cinamon
  • 939
  • 5
  • 16