tags:

views:

65

answers:

4

From command line i am getting file name which i have to compile using gcc. lets say its like this.

./a.out fileToBeCompiled.c

Then how i can compile this file using gcc within my program? lets say main.c for which a.out is being made.

+2  A: 

You can always call gcc to compile from an shell execution command within your program.

Reference to the system function.

monksy
Thanks, it work for me.
itsaboutcode
Using system is a bad idea, but if it works for itsaboutcode, it shall be fine with me
ammoQ
+2  A: 

Just exec gcc from within you program.

int main(int argc, char** argv)
{
   execv("/usr/bin/gcc", argv);
}
stimms
+1  A: 

Learn how to call fork(), exec(), and wait(). You probably want to use execv() for this purpose.

D.Shawley
A: 
./a.out fileToBeCompiled.c && gcc fileToBeCompiled.c

If ./a.out fails (it it returns something other than 0) gcc will not be called

pmg