c语言 - spawn() 函数(在 "spawn.h" 中声明)从何而来?

  • 本文关键字:spawn 声明 函数 语言 c spawn
  • 更新时间 :
  • 英文 :


我无法编译这个简单的程序

#include<stdio.h>
#include<conio.h>
#include<spawn.h>
#include<process.h>
int main(){
    printf("Spawning new process...n");
    spawnl(P_WAIT,"curl","www.google.co.in",NULL);
    system("cls");
    printf("Program execution completed somehow!n");
    getch();
    return 0;
}

我已经尝试使用以下命令:

g++ filename.cpp -l -o filename.cpp

结果:ld.exe cannot find -l exit with status 1

g++ filename.cpp -o filename

结果:error: spawn.h No such file or directory.

我的MinGW安装有问题吗?我使用的是Windows 7 32位和MinGW。

spawn.h不是标准的C/C++标头。POSIX定义了一个非标准的<spawn.h>头,但它没有定义spawnl函数,而且Windows无论如何都不是一个符合POSIX的系统。

Windows确实在<process.h>中定义了_spawnl函数,所以最简单的方法就是删除<spawn.h>的包含,然后使用它。您也可以重写代码以使用Windows函数CreateProcess

最新更新