I have used the crypt function in c to encrypt the given string.
I have written the following code,
#include<stdio.h>
#include<unistd.h>
int main()
{
printf("%s\n",crypt("passwd",1000));
}
But the above code threw an error ,”undefined reference to `crypt'”.
What is the problem in the above code.
Thanks in advance.
If you want to use the
crypt()function, you need to link to the library that supplies it. Add-lcryptto your compile command.Older versions of glibc supplied a
libcryptlibrary for this purpose, and declared the function in<unistd.h>– to compile against this support, you may also need to define either_XOPEN_SOURCEor_GNU_SOURCEin your code before including<unistd.h>.Newer versions of glibc don’t supply
libcrypt– it is instead provided by a separatelibxcrypt. You still link with-lcrypt, but the function is instead declared in<crypt.h>.