本文介绍了是的crypt()函数unistd.h中或crypt.h声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GCC 4.6.0(上的其它身份不明的平台的)。

I'm using GCC 4.6.0 (on an otherwise unidentified platform).

我使用的是的crypt()函数加密的密码。

I am using the crypt() function to encrypt a password.

我从来没有使用该功能之前,所以我检查了主要的页面:

I have never used that function before so I checked out the main page:

man 3 crypt

和它说包含 unistd.h中头。

然而,当我这样做,我得到了地穴函数进行隐含的警告。

However, when I did that, I got an implicit warning for the crypt function.

warning: implicit declaration of function ‘crypt’ [-Wimplicit-function-declaration]

我做了一些搜索和我发现,你必须包括 crypt.h 。但是,怎么来的不说,在手册页?

I did a bit of searching and I found that you have to include the crypt.h. However, how come it doesn't say that in the man page?

推荐答案

它还说的#define _XOPEN_SOURCE (包括前unistd.h中)。所以,你应该把它添加到暴露隐窝声明

It also says #define _XOPEN_SOURCE (before including unistd.h) in my man page. So you should probably add it to expose the declaration of crypt.

修改

我刚刚试了一下。包括 unistd.h中的#define _XOPEN_SOURCE 它的伎俩了。包括单打独斗是不够的。

I just tried it. Including unistd.h and #define _XOPEN_SOURCE before it does the trick. Including it alone isn't enough.

使用

gcc version 4.6.0 20110429
GNU C Library stable release version 2.13

展望 unistd.h中

/* XPG4.2 specifies that prototypes for the encryption functions must
   be defined here.  */
#ifdef  __USE_XOPEN
/* Encrypt at most 8 characters from KEY using salt to perturb DES.  */
extern char *crypt (__const char *__key, __const char *__salt)
     __THROW __nonnull ((1, 2));

这篇关于是的crypt()函数unistd.h中或crypt.h声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 09:26