Compile c file by source code -


i'm writing code got path c file, , want compile file program code. meaning compile not in command line like:

gcc -o a.out file.c 

there way it?

if trying compile c source file in programmatic manner, can try this:

execlp("gcc", "gcc", "file.c", "-o", "a.out", null); 

execlp has advantage of searching dirs stored in environment $path find required executable. returns -1 if call fails. don't forget #include <unistd.h> work.

you can away simple call:

system("gcc file.c -o a.out"); 

this requires #include <stdlib.h> , execute gcc invoking /bin/sh.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -