简体   繁体   中英

run a command with execvp in c program

I want to run this command with execvp

gcc file1.o file2.o file3.o

I created a tab wich contain this :

char * tab = {"file1.o", "file2.o", "file3.o", NULL };

when I call execvp like that :

 execvp("gcc",tab);

I have this error :

file1.o: erreur fatale: -fuse-linker-plugin, but liblto_plugin.so not found

When I compile the files using :

gcc file1.o file2.o file3.o

there is no problem.

Note my program is not like that I wrote it like that to simplify. for the complete code look visit http://pastebin.com/zQ8pwmZd

The first element of the argv array passed to execvp (ie, the second argument passed to execvp ) should be (just like with the argv array passed to the main function of any C program) the name of the program being executed, with the element after that being the first command-line argument. Thus, tab should be:

char * tab[] = {"gcc", "file1.o", "file2.o", "file3.o", NULL };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM