GCC(GNU Compiler Collection)은 개발 도구 및 컴파일러 세트이다. 이러한 GCC는 Windows, Linux 등의 다양한 플랫에서 사용할 수 있다. 이 글에서는 Ubuntu 22.04 LTS 에 GCC를 설하는 방법에 대해 알아본다.
1. GCC 설치
GCC를 설치하기 전에 패키지 업데이트를 먼저 해주고, build-essential
패키지를 설치하여 GCC가 설치되도록 한다.
$ sudo apt update
$ sudo apt install build-essential -y
2. GCC 버전 확인
“gcc –version” 을 실행하여 설치된 gcc 버전을 확인한다.
$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.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. 빌드하기
아래와 같이 “Hello World!!”를 출력하는 hello.c를 작성하고, 컴파일 한다.
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello World!!\n");
return 0;
}
$ gcc hello.c
컴파일 결과로 생성된 실행 바이너리인 a.out을 file
명령으로 정보를 확인한다.
$ file a.out
a.out: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=358ba7b0f9128416bd681f4572238836a37db61b, for GNU/Linux 3.2.0, not stripped
a.out이 제대로 실행되는지 실행시켜본다.
$ ./a.out
Hello World!!