带地穴的 CMake(3)
CMake with crypt(3)
我正在尝试使用 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 = "$/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})
如何传递这个选项并构建它?
类似于:
target_link_libraries(check crypt)
来源:https://cmake.org/cmake/help/latest/command/target_link_libraries.html
我正在尝试使用 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 = "$/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})
如何传递这个选项并构建它?
类似于:
target_link_libraries(check crypt)
来源:https://cmake.org/cmake/help/latest/command/target_link_libraries.html