我想用 c 编写一个程序来编译和运行另一个程序。我写了这段代码,它返回了这个:
robi@Robi:~$ ./comp test.c
gcc: fatal error: no input files
compilation terminated.
Error
我是这样编译的:
gcc -Wall -o comp Compilare.c
然后像这样运行它:
./comprun test.c
test.c是这个
#include<stdio.h>
int main(){
printf("Ana are mere");
return 0;
}
代码:
#include<stdio.h>
#include<sys/wait.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
int main(int argc,char* argv[]) {
char comanda[100];
strcpy(comanda,"gcc -o run");
strcat(comanda,argv[1]);
if(WEXITSTATUS(system(comanda) == 0))
execl("./run","./run",NULL);
printf("Error");
return 0;
}
如何让它无错误地运行?
最佳答案
问题是您在程序中调用的 gcc
命令看起来像这样:gcc -o runtest.c
,即它试图编译没有输入到输出名为 runtest.c
的二进制文件。您需要在字符串文字的末尾留一个空格:"gcc -o run"
-> "gcc -o run "
关于c - 将一个程序编译运行到另一个程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43947038/