未定义对"crypt"的引用 [英] undefined reference to `crypt'
本文介绍了未定义对"crypt"的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用下面的代码,这些代码是我在网上找到的,尝试构建它时出现错误.编译正常.
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.
这是错误:
/tmp/ccCnp11F.o: In function `main':
crypt.c:(.text+0xf1): undefined reference to `crypt'
collect2: ld returned 1 exit status
这是代码:
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <crypt.h>
int main()
{
unsigned long seed[2];
char salt[] = "$1$........";
const char *const seedchars =
"./0123456789ABCDEFGHIJKLMNOPQRST"
"UVWXYZabcdefghijklmnopqrstuvwxyz";
char *password;
int i;
/* Generate a (not very) random seed.
You should do it better than this... */
seed[0] = time(NULL);
seed[1] = getpid() ^ (seed[0] >> 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. */
puts(password);
return 0;
}
推荐答案
crypt.c:(.text+0xf1): undefined reference to 'crypt'
是链接器错误.
尝试与-lcrypt
链接:gcc crypt.c -lcrypt
.
这篇关于未定义对"crypt"的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文