c - 将一个程序编译运行到另一个程序时出错

标签 c linux

我想用 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/

相关文章:

c - 调试剥离程序时在 gdb 中加载伪调试符号

linux - 如何发送通知(电子邮件、短信等)隐秘地编程 linux

python - 使用 pip 安装 python 包与从 Linux 存储库安装

c - 添加两个大数字作为字符串

c - 我的角色搜索循环

c - 有哪些重构方法可以减少编译代码的大小?

linux - ffmpeg结合了压缩和水印两个命令

html - 如何在bash中仅使用grep提取html标签

c - 搜索/打印数组中的特定元素

c - 为什么代码显示两个不同变量的相同值,temp 既不是本地也不是全局,什么是 temp?