0

I am unable to compile this simple program

#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;
}

I have tried using following command:

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

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

g++ filename.cpp -o filename

Result: error: spawn.h No such file or directory.

Is there a problem with my MinGW installation? I am using Windows 7 32 bit and MinGW.

vish213
  • 748
  • 3
  • 12
  • 27
  • Why you don't use std::cout instead of printf()? –  Aug 21 '12 at 21:43
  • what is (where is it from) spawn/spwan.h? It certainly is not standard C++. Otoh, nothing in your program seems to hint that it is C++, so are you sure you want a C++ answer and not a C answer? – PlasmaHH Aug 21 '12 at 21:45
  • @pst : IDK. I have been googling for it. It wasn't on my system, I download this and some other related .h files but than some other errors kept coming. So I removed them too. I am windows user and finding it very difficult to manage this library stuff while compiling. Do I need to download some library? – vish213 Aug 21 '12 at 21:49
  • @R.M. :R.M. : Was coding in C for past some months, then decieded to go to C++ for this particular program only, because I love the concept of classes. So now writing most of program in C, except for using some features of C++ – vish213 Aug 21 '12 at 21:50
  • @PlasmaHH: Changed the tag. I am myself trying to figure out which library contains this,whether it is or not on my system. I am used to code in Java and everything seems to be in one place there. Now this library thing for every function I use-pthread, spawn and similar functions making me look like a fool. – vish213 Aug 21 '12 at 21:59
  • @vish213 Ok. In this case the C tag is more appropriated: I saw you changed it. ;) –  Aug 21 '12 at 22:00

1 Answers1

3

spawn.h is not a standard C/C++ header. POSIX defines a non-standard <spawn.h> header, but it doesn't define a spawnl function, and Windows is not a POSIX-conforming system anyways.

Windows does define the _spawnl function in <process.h>, so the easiest thing to do would be to just remove the inclusion of <spawn.h> and use that instead. You could also rewrite your code to use the Windows function CreateProcess.

Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589
  • 2
    The POSIX spawning functions all start with `posix_`, so the code can't be intending to use [POSIX ``](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/spawn.h.html#tag_13_44). And neither `` nor `` is a POSIX header, either. – Jonathan Leffler Aug 21 '12 at 21:48
  • Means-Install Cygwin, and compile it there. Will my somehow compiled program run on Windows system NOT having Cygwin? – vish213 Aug 21 '12 at 21:54
  • http://en.wikipedia.org/wiki/Spawn_(computing) Someone gave me this link. Am I getting something wrong? – vish213 Aug 21 '12 at 22:13
  • @vish213: That link is essentially correct, except the functions have been renamed to have a leading underscore. Nowhere does that article mention any header named ``, except for a reference to article mentioning the different POSIX functions. – Adam Rosenfield Aug 21 '12 at 22:18