首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >收到警告“函数‘strlen’的隐式声明”

收到警告“函数‘strlen’的隐式声明”
EN

Stack Overflow用户
提问于 2013-11-04 11:15:34
回答 2查看 72.3K关注 0票数 28

我有一个简单的代码,但我收到一个警告:

-bash-3.2$ gcc -Wall print_process_environ.c -o p_p
print_process_environ.c: In function 'print_process_environ':
print_process_environ.c:24: warning: implicit declaration of function 'strlen'
print_process_environ.c:24: warning: incompatible implicit declaration of built-in function 'strlen'

代码如下:

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <strings.h>

    void
    print_process_environ(pid_t pid)
    {
        int     fd;
        char    filename[24];
        char    environ[1024];
        size_t  length;
        char    *next_var;

        snprintf(filename, sizeof(filename), "/proc/%d/environ", (int)pid);
        printf("length of filename: %d\n", strlen(filename));

        fd = open(filename, O_RDONLY);
......

strlen()的定义是:

   #include <string.h>

   size_t strlen(const char *s);

如何摆脱这个警告。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-11-04 11:17:03

我是#include <string.h>。您在代码中拼写错误。另外,如果您的编译器中出现了该警告..始终在终端上执行man function_name以查看该函数所需的标头

 #include <string.h> // correct header
 #include <strings.h> // incorrect header - change this in your code to string.h
票数 45
EN

Stack Overflow用户

发布于 2016-08-07 06:12:44

原来代码是#include <stdlib.h>,我的输出是:

解决方案:

stdlib.h更改为stdio.h,警告已消失

简而言之,编译器试图告诉您它找不到函数的声明。这是一个)的结果。不包含头文件b)错误的头文件名.eg“sring.h”

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19761104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档