mkdir的隐式声明

Sea*_*ado 2 c makefile function

对于我的问题,让我假设我有两个函数,它们都是在库文件夹中的.h文件中的原型,以及.c辅助文件中的实现(如下所示),我将在我的程序中使用它们.

calsis.c

 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include "include/calsis.h" /* Extern header */ 

char folder_name[30] = "Information";

void no_args() /* Function 1 */
{
  printf("Hello, world!\n");

   if ( mkdir(folder_name, S_IRWXU) == -1 )
    perror("Can't create a new folder");
}

void with_args(char *foo) /* Function 2 */
{
   printf("Hello, world!\n");
   printf("Name: %s\n", foo);

   if ( mkdir(folder_name, S_IRWXU) == -1 )
    perror("Can't create a new folder");
}
Run Code Online (Sandbox Code Playgroud)

对于稍后我会做的事情,我需要在两个函数中创建一个带有mkdir的文件夹,但是,在通过编译带有实现函数的.c文件生成目标文件calsis.o时,使用GCC编译给了我警告mkdir函数是隐含声明的.

我有什么想法可以删除这个警告吗?

P.P*_*.P. 7

您尚未包含标题mkdir:

来自man(2)mkdir:

SYNOPSIS
       #include <sys/stat.h>
       #include <sys/types.h>

       int mkdir(const char *pathname, mode_t mode);
Run Code Online (Sandbox Code Playgroud)