Ubuntu20.04 gccをインスールして実行する手順

Ubuntu20.04 gccをインスールして実行する手順

Ubuntu20.04にgcc(GNU Compiler Collection) Cコンパイラーをインスールして実行する手順を記述してます。

環境

  • OS  ubuntu20.04
  • gcc 9.3.0

gccインスール

開発パッケージをインストール します。

sudo apt install build-essential

gccのバージョンを確認してみます。

gcc --version

<出力結果>
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Hello Worldしてみる

C言語をコンパイルして「Hello World」してみます。

vi hello.c

下記の通りに編集してます。

#include <stdio.h>
int main()
{
   printf("Hello World");
   return 0;
}

コンパイルします。

gcc -o hello hello.c

実行します。

./hello

<出力結果>
Hello World

「Hello World」が表示されることが確認できます。