I am trying to use crypt function like this (I’m new to C, this is just for learning)
#include<stdio.h>
#define _XOPEN_SOURCE
#include <unistd.h>
char *crypt(const char *key, const char *salt);
int main()
{
char* key="ilya";
char* salt="xx";
char* password=(char*)crypt(key, salt);
printf("%s\n", password);
return 0;
}
I compile it using make filename
And I get the following error:
/home/bla/password.c:20: undefined reference to `crypt'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Why is that?
(I know it is a very lousy way to encrypt things, this is just for learning purposes)
Try
gcc file.c -o file -lcryptto link the libcrypt library if you’re running Linux.You can remove the
(char*)cast from callingcrypt(), it already returns achar *and also the declaration of thecrypt()function since it’s already provided fromunistd.h.I also suggest you change this:
to
Since they are pointing to read-only memory and will produce a
SIGSEGV(Segmentation fault signal) if you try to modify the content they point to.