2016-03-27 8 views
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}) 

は、どのように私は、このオプションを渡し、それを構築することができますか?

答えて