When the compiler complains that it cannot force the type of thing you are passing as argument to the type of thing it wants for argument, that is a strong clue that you are giving the function the wrong kind of thing.
The
execv() functions expect an argument
array. The way you appear to be trying to use it, you want to use the
execlp() function. Don't forget also that the last argument must be
NULL
.
It is very important to
pay attention to the man pages. You cannot just skim over them and wonder why things didn't work when you did things the way
you thought they would work.
http://linux.die.net/man/3/execvp
1 2
|
// Execute the GCC
execlp( "gcc", "gcc", "main.o", "quux.o", "foo.o", NULL );
|
If you want to supply a variable selection of files to compile, you'll have to incorperate that into the argument list you give to
execvp():
1 2 3 4
|
// How exactly you create this list is up to you...
char* args[] = { "gcc", "main.o", "quux.o", "foo.o", NULL };
// Now execute it
execvp( args[ 0 ], args );
|
I presume that you successfully called
fork() before executing this function, right?
http://linux.die.net/man/2/fork
For all this grief, why don't you just use
system() from your main program?
http://linux.die.net/man/3/system
Hope this helps.