【问题标题】:Implicit declaration of function ‘wait’函数“等待”的隐式声明
【发布时间】:2017-06-12 14:05:01
【问题描述】:

我收到警告 > 函数“等待”的隐式声明

提前致谢

编辑:我忘记添加包含的库

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


void create (char* program, char** arg_list)
{
  /* put your code here */
  pid_t childPid;
  int status;

  if((childPid = fork()) < 0){
    printf("Failed to fork() --- exiting...\n");
    exit(1);
  }
  else if (childPid == 0){ // --- inside the child process
    if(execvp(program, arg_list) < 0){ // Failed to run the command
      printf("*** Failed to exec %s\n", program);
      exit(1);
    }
  }
  else{ // --- parent process
    while(wait(&status) != childPid)
      printf("...\n");
  }
}

【问题讨论】:

  • 您缺少函数的 #include 行。

标签: c wait pid


【解决方案1】:

你需要输入:

#include <sys/types.h>
#include <sys/wait.h>

在程序顶部获取函数的声明。

这显示在man page

【讨论】:

    【解决方案2】:

    您可能缺少wait(2) 的标题:

      #include <sys/types.h>
      #include <sys/wait.h>
    

    【讨论】:

    • 谢谢,我忘了等待库
    猜你喜欢
    • 2021-01-20
    • 1970-01-01
    • 2014-06-28
    • 2022-01-16
    • 2011-10-05
    • 2013-10-28
    • 2019-07-16
    • 2017-07-16
    相关资源
    最近更新 更多