반응형
경고 수신 "기능 'strlen'에 대한 암묵적 선언"
간단한 코드를 가지고 있지만 경고를 받고 있습니다.
-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);
이 경고를 없애는 방법.
그건…#include <string.h>. 당신의 코드에서 철자를 잘못 쓰고 있습니다.그리고 만약 당신이 당신의 컴파일러에 그런 경고를 받게 된다면..늘 하는 일man function_name해당 기능에 필요한 헤더를 보기 위해 단말기에서
#include <string.h> // correct header
#include <strings.h> // incorrect header - change this in your code to string.h
당신은 실수하기 쉬운 실수에 물렸고, 포식스 줄을 포함했습니다.h 헤더:
#include <strings.h>
대신:
#include <string.h>
posix 헤더는 다음을 지원합니다.
int bcmp(const void *, const void *, size_t); (LEGACY )
void bcopy(const void *, void *, size_t); (LEGACY )
void bzero(void *, size_t); (LEGACY )
int ffs(int);
char *index(const char *, int); (LEGACY )
char *rindex(const char *, int); (LEGACY )
int strcasecmp(const char *, const char *);
int strncasecmp(const char *, const char *, size_t);
모두 비표준 함수이며 오류가 없다는 것을 설명해 줍니다. 좋은 참조를 찾는데 어려움을 겪고 있지만 bSD 시스템 버전의 string.h에도 string.h가 포함되어 있었습니다.
알고 보니 암호는#include <stdlib.h>결과는 다음과 같습니다.
해결책:
변경되었다.stdlib.h로.stdio.h그리고 경고는 사라졌습니다.
간단히 말해서, 컴파일러는 함수의 선언을 찾을 수 없었다고 말하려 합니다.이는 a)의 결과입니다.포함된 헤더 파일이 없습니다. b) 잘못된 헤더 파일 이름.예" sring.h"
언급URL : https://stackoverflow.com/questions/19761104/receiving-warning-implicit-declaration-of-function-strlen
반응형
'programing' 카테고리의 다른 글
| MySQL 구문 오류 - JSON (0) | 2023.10.14 |
|---|---|
| 파일 또는 stdin에서 읽기 (0) | 2023.10.14 |
| 부트스트랩 3 RC 1에서 type ahead 자바스크립트 모듈은 어디에 있습니까? (0) | 2023.10.14 |
| Oracle: tablea, tableb에서 *를 선택합니다. 여기서 a.fielda (+)=b.fieldb -- (+)란 무엇입니까? (0) | 2023.10.14 |
| gcc는 왜 오랫동안 경고를 가지고 있습니까? (0) | 2023.10.14 |
