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
Post a Comment