I would like to use the password-hashing function Argon2 in my C++ application. But I get a error if I build the application:
error while loading shared libraries: libargon2.so.0: cannot open shared object file: No such file or directory
What I did so far: I downloaded the source in a subfolder of my Qt project folder (thirdparty > Argon2). Called make
to build the Argon .so and verified with make test
that everything is ok. The project structure looks like this:
testproject > CMakeLists.txt
testproject > application > test > impl > src > Main.cpp
testproject > thirdparty > Argon2 > include > argon2.h
testproject > thirdparty > Argon2 > libargon2.so
In my CMakeLists I added Argon include path and TRIED to link against the .so file:
find_library(Argon2 NAMES libargon2 PATHS ${CMAKE_SOURCE_DIR}/thirdparty/Argon2)
# Additional include directories
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/thirdparty/Argon2/include
target_link_libraries(${COMPONENT_NAME} ${Argon2})
But this simple test program will give me the above mentioned error.
#include "argon2.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define HASHLEN 32
#define SALTLEN 16
#define PWD "password"
int main(){
uint8_t hash1[HASHLEN];
uint8_t salt[SALTLEN];
memset( salt, 0x00, SALTLEN );
uint8_t *pwd = (uint8_t *)strdup(PWD);
uint32_t pwdlen = strlen((char *)pwd);
uint32_t t_cost = 2; // 1-pass computation
uint32_t m_cost = (1<<16); // 64 mebibytes memory usage
uint32_t parallelism = 1; // number of threads and lanes
argon2i_hash_raw(t_cost, m_cost, parallelism, pwd, pwdlen, salt, SALTLEN, hash1, HASHLEN);
}
I'm still very new to C++ and CMake, so I don't know if my procedure was correct (obviously not, because it does not work).
- Is it possible to link only the .so file?
- Will I have to include the whole directory of the Argon library in my project (like I tried)?
- What are the necessary steps to tell my linker how to find the library correctly?
EDIT
This post seems to be similar to mine. But I can't figure out be their answers if the .so file would be sufficient and how to link against a library which is not installed by the package manager of my debian system.