I am using the below code that i found somewhere in the net and i am getting an error when i try to build it. The compilation is ok.
Here is the error:
/tmp/ccCnp11F.o: In function `main':
crypt.c:(.text+0xf1): undefined reference to `crypt'
collect2: ld returned 1 exit status
unsigned long seed;
char salt = "$1$........";
const char *const seedchars =
/* Generate a (not very) random seed.
You should do it better than this... */
seed = time(NULL);
seed = getpid() ^ (seed >> 14 & 0x30000);
/* Turn it into printable characters from `seedchars'. */
for (i = 0; i < 8; i++)
salt[3+i] = seedchars[(seed[i/5] >> (i%5)*6) & 0x3f];
/* Read in the user's password and encrypt it. */
password = crypt(getpass("Password:"), salt);
/* Print the results. */
crypt.c:(.text+0xf1): undefined reference to 'crypt' is a linker error. Try linking with
gcc crypt.c -lcrypt.
You may also need to define
_GNU_SOURCE. Also see the
man 3 crypt manual page.