使用system()编译源文件,’主要从可执行文件的隐式条目/启动引用

我已经针对同一个问题两次发布了同样的问题,所以如果有兴趣,你可以继续我的个人资料,找到我最初提出的问题的答案。

这是我的作业代码。 家庭作业的重点是写一个“评分者”计划。 我只是要求用户输入文本文件,并给我命名。 以及源文件。 然后我将源文件与txt文件一起编译,并将其与预期的输出(用户也提供给我)进行比较。 我正在尝试使用系统函数编译程序。 不要混淆system()允许用户从C程序运行UNIX命令。 当我尝试编译用户提供的源文件时,我收到一条错误信息

 "_main", referenced from: implicit entry/start for main executable. clang: error: linker command failed with exit code 1 (use -v to see invocation) sh: ./myProg: No such file or directory 

我不知道这意味着什么,我从昨晚开始就遇到这个错误,似乎无法找到问题所在

谢谢!

 #include  #include  #include  #define NUM_LINES 5 int main(){ char srcfile[200]; char inpfile[200]; char resultfile[200]; printf("Please enter the name of the source file: \n"); scanf("%s",srcfile); printf("Please enter the name of the input file: \n"); scanf("%s",inpfile); printf("Please enter the name of the expected result file: \n"); scanf("%s",resultfile); char test1 [100]="gcc -o myProg "; char test2 [100]="./myProg "; strcat(test2,inpfile); strcat(test2," > "); strcat(test2,resultfile); strcat(test1,srcfile); printf("%s\n",test1); //these are just tests printf("%s",test2); //these are just tests if (system(test1)) { printf("There is an error compiling the program "); } if (system(test2)!= 0) { printf("There is an error running the executable"); } return 0; } 

错误不在您发布的评分程序中。 错误位于您正在“评分”的源文件中。 使用gcc编译该源文件以查看并修复错误。

编译完成后,您发布的程序也会运行正常。