[英]How to link Argon2 library with cmake in Qt Creator
我想在我的 C++ 应用程序中使用密码散列函数Argon2 。 但是如果我构建应用程序,我会收到一个错误:
error while loading shared libraries: libargon2.so.0: cannot open shared object file: No such file or directory
到目前为止我所做的:我在 Qt 项目文件夹(第三方 > Argon2)的子文件夹中下载了源代码。 调用make
来构建 Argon .so 并通过make test
验证一切正常。 项目结构如下所示:
testproject > CMakeLists.txt
testproject > application > test > impl > src > Main.cpp
testproject > thirdparty > Argon2 > include > argon2.h
testproject > thirdparty > Argon2 > libargon2.so
在我的 CMakeLists 中,我添加了 Argon 包含路径并尝试链接到 .so 文件:
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})
但是这个简单的测试程序会给我上面提到的错误。
#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);
}
我对 C++ 和 CMake 还是很陌生,所以我不知道我的程序是否正确(显然不是,因为它不起作用)。
编辑
这个帖子好像和我的一样。 但是我无法弄清楚 .so 文件是否足够以及如何链接到我的 debian 系统的包管理器未安装的库,他们的答案是什么。
在project/
目录中的project/
我使用CMakeLists.txt
project/argon2/
克隆到project/argon2/
...
target_include_directories(target PUBLIC argon2/include)
target_link_libraries(target argon2)
在代码中,我通过#include <argon2.h>
包含 Argon2,它对我#include <argon2.h>
。
对我有用的是下载存储库并在其中运行make
命令。 这应该创建静态库libargon2.a
。 然后在你的 CMakeLists.txt 添加
include_directories(libs/argon2/include)
link_directories(libs/argon2)
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} argon2)
其中libs/argon2
表示下载的存储库的相对路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.