I'm looking to make a program with the purpose of compiling another. The purpose being using exec to run gcc. I have to use execve and what I have is:
#include <unistd.h>
#include <sys/types.h>
int main(int argc, char* argv[], char* envp[])
{
argv[0] = "gcc";
execve("/usr/bin/gcc" , argv, envp);
return 0;
}
By doing
gcc -Wall p3p4.c -o run
It compiles without problems, but when doing
./run p3p1.c
To try and compile another one, this happens:
run: error trying to exec 'cc1': execvp: No such file or directory
EDIT:
As advised, when adding the line:
argv[0] = "gcc";
The program manages to work. Thank you for the input.