步骤1:做成 test.c文件
#include<stdio.h>
void main()
{
printf("hello world!\n");
}
步骤2:用gcc(GNU Compiler Collection,简称GNU编译工具集)编译生成test实行文件
gcc test.c -o test
失败,提示如下找不到gcc。
Command 'gcc' not found, but can be installed with:sudo apt install gcc
执行:sudo apt install gcc 安装gcc。
失败,提示如下需更新:
Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/l/linux/linux-libc-dev_4.15.0-191.202_amd64.deb 404 Not Found [IP: 91.189.91.39 80]Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
执行:sudo apt-get update更新,再执行 sudo apt install gcc 即可成功。
再次执行: gcc text.c -o test
失败,提示如下,已经有同名文件,删除掉原来的或重命名即可成功
/usr/bin/ld: cannot open output file test: Is a directory
collect2: error: ld returned 1 exit status
重命名实行文件:gcc text.c -o test1 成功
用ls 命令查看,已经生成test1实行文件
步骤3:sh调用test1实行文件
创建一个空的sh文件:test1.sh
打开文件,输入以下执行命令,保存
"./test1"
步骤4:执行sh文件
./test1.sh
输出:hello world!
※当然直接执行test1实行文件也可以运行
./test1
输出:hello world!