本文介绍了mkdir的隐式声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For my question let's suppose I have two functions, both of them with the prototypes on a .h file in a library folder, and the implementation in a .c auxiliary file (shown below), and I will use both of them in my program.

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");
}

对于以后要执行的操作,我需要在两个函数中都使用mkdir创建一个文件夹,但是在通过编译.c文件来生成目标文件 calsis.o 时,在实现的函数中,使用GCC进行编译会警告我 mkdir函数是隐式声明的.

For something I will do later, I need in both functions to create a folder with mkdir, but, in the generation of the object file calsis.o by the compilation of the .c file with the implemented functions, the compilation with GCC gives me a warning that the mkdir function is implicity declared.

有什么主意我可以删除此警告吗?

Any idea I can remove this warning?

推荐答案

您尚未包含mkdir的标题:

来自man(2)mkdir:

From man(2) mkdir:

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

       int mkdir(const char *pathname, mode_t mode);

这篇关于mkdir的隐式声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 13:02