密码函数和链接错误

密码函数和链接错误

本文介绍了密码函数和链接错误“未定义对“密码"的引用";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在c语言中使用了crypt函数来加密给定的字符串.我已经编写了以下代码,

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));
}

但是上面的代码抛出了一个错误,未定义对"crypt"的引用".上面的代码有什么问题.

But the above code threw an error ,"undefined reference to `crypt'".What is the problem in the above code.

提前谢谢.

推荐答案

如果要使用crypt()函数,则需要链接到提供它的库.将-lcrypt添加到您的编译命令中.

If you want to use the crypt() function, you need to link to the library that supplies it. Add -lcrypt to your compile command.

较早版本的glibc为此提供了一个libcrypt库,并在<unistd.h>中声明了该功能-为了对此支持进行编译,您可能还需要在代码中定义_XOPEN_SOURCE_GNU_SOURCE包括<unistd.h>.

Older versions of glibc supplied a libcrypt library for this purpose, and declared the function in <unistd.h> - to compile against this support, you may also need to define either _XOPEN_SOURCE or _GNU_SOURCE in your code before including <unistd.h>.

较新版本的glibc不提供libcrypt-而是由单独的libxcrypt提供.您仍然与-lcrypt链接,但是该函数改为在<crypt.h>中声明.

Newer versions of glibc don't supply libcrypt - it is instead provided by a separate libxcrypt. You still link with -lcrypt, but the function is instead declared in <crypt.h>.

这篇关于密码函数和链接错误“未定义对“密码"的引用";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:31