我有一个简单的代码,但我收到一个警告:
-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);
如何摆脱这个警告。
发布于 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
发布于 2016-08-07 06:12:44
原来代码是#include <stdlib.h>
,我的输出是:
解决方案:
将stdlib.h
更改为stdio.h
,警告已消失
简而言之,编译器试图告诉您它找不到函数的声明。这是一个)的结果。不包含头文件b)错误的头文件名.eg“sring.h”
https://stackoverflow.com/questions/19761104
复制相似问题