我尝试使用CMake制作crypt(3)
样本。
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <crypt.h>
/* To compile: $ gcc check.c -lcrypt -o check */
int main(void) {
/* Hashed form of "GNU libc manual". */
char *pass = "$1$/iSaq7rB$EoUw5jJPPvAPECNaaWzMK/";
/* Read in the user’s password and encrypt it,
passing the expected password in as the salt. */
char *result = crypt(getpass("Password:"), pass);
/* Test the result. */
int ok = strcmp (result, pass) == 0;
puts(ok ? "Access granted." : "Access denied.");
return ok ? 0 : 1;
}
要构建它,应该将-lcrypt
选项传递给gcc。
我的CMakeLists.txt
看起来像是:
project(cryptexample)
set(SOURCE_FILES check.c)
add_executable(check ${SOURCE_FILES})
如何通过此选项并构建它?
答案 0 :(得分:3)
类似的东西:
target_link_libraries(check crypt)
来源:https://cmake.org/cmake/help/latest/command/target_link_libraries.html