温馨提示×

ubuntu如何编译运行c程序

小亿
83
2024-08-23 01:38:30
栏目: 智能运维

在Ubuntu上编译和运行C程序通常需要安装编译器和构建工具。以下是使用gcc编译和运行C程序的步骤:

  1. 安装gcc编译器和构建工具:
sudo apt update
sudo apt install build-essential
  1. 创建一个C源文件,比如hello.c,编辑并保存:
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}
  1. 使用gcc编译hello.c源文件:
gcc hello.c -o hello

这将生成一个可执行文件hello。

  1. 运行生成的可执行文件:
./hello

这将输出"Hello, World!"。

以上是在Ubuntu上编译和运行C程序的基本步骤。您可以根据自己的程序和需求进行相应的调整和操作。

0