Ubuntu 22.04にgccコンパイラーをインスールする

環境
Ubuntu 22.04.1 LTS
gcc 11.2.0

操作方法
1.開発パッケージをインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo apt install build-essential
# sudo apt install build-essential
# sudo apt install build-essential

2.gccのバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# gcc --version
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Copyright (C) 2021 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.
# gcc --version gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0 Copyright (C) 2021 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.
# gcc --version
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Copyright (C) 2021 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.

3.動作確認
# nano test.c
以下のコードを記述します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <stdio.h>
int main()
{
printf("Hello World study c language");
return 0;
}
#include <stdio.h> int main() { printf("Hello World study c language"); return 0; }
#include <stdio.h>
int main()
{
   printf("Hello World study c language");
   return 0;
}

ファイルをコンパイルします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# gcc -o test test.c
# gcc -o test test.c
# gcc -o test test.c

コンパイルしたファイルを実行します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# ./test
Hello World study c language
# ./test Hello World study c language
# ./test
Hello World study c language

 

Ubuntu 22.04

Posted by arkgame