简体   繁体   English

如何在脚本中运行gcc命令到exe main.c

[英]how to run gcc command in script to exe main.c

I'm new in linux trying to run .C program from another directory in script. 我是Linux新手,试图从脚本中的另一个目录运行.C程序。 script is in home directory and .C program is in Desktop directory. 脚本位于主目录中,而.C程序位于桌面目录中。 here is script. 这是脚本。

#!/bin/bash
chmod 777 myscript
cd /home/unifi-007/Desktop/
gcc main -o main.c
./main

But i'm not getting it right. 但是我做错了。 how to execute main.c in script. 如何在脚本中执行main.c。

The usage of gcc is clearly wrong, it should be gcc -o main main.c . gcc的用法显然是错误的,应该是gcc -o main main.c

BTW, .C is a suffix for C++ (at least for GCC it is), not C. 顺便说一句, .C是C ++的后缀(至少对于GCC是),而不是C。

BTW again, normally, you do not run a C source file, you compile it, and run the executable file generated by compiler (by linker, actually). 顺便说一句,通常,您通常不运行 C源文件,而是对其进行编译 ,然后运行由编译器(实际上是通过链接器)生成的可执行文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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