0
我試圖用CMake製作crypt(3)
樣本。CMake with 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})
我怎樣才能通過這個選項,並建立它?