Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling program within another program using gcc

Tags:

c

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.

like image 747
itsaboutcode Avatar asked Dec 18 '22 04:12

itsaboutcode


2 Answers

Just exec gcc from within you program.

int main(int argc, char** argv)
{
   execv("/usr/bin/gcc", argv);
}
like image 52
stimms Avatar answered Jan 03 '23 22:01

stimms


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

Reference to the system function.

like image 31
monksy Avatar answered Jan 03 '23 22:01

monksy