본문 바로가기
IT/LINUX

리눅스 CentOS C++ 컴파일러 설치하기

by SidePower 2022. 10. 6.

 

클래스와 객체가 있는 c++ 개발언어의 소스파일은 cpp입니다.

cpp 파일을 컴파일하려면 리눅스 C++ 컴파일러를 설치해야 되는데요.

c++ 공부하려는 건 아니고 얼마 전에 오픈소스 하나를 사용하려고

다운로드하여 빌드하는 과정에서 에러를 보니

원인이 오픈소스에 cpp파일이 많이 포함되어 있었고 c++ 컴파일러가 없다는 것이었죠.

 

예전에 아주 잠깐 c++ 공부했던 기억이 되살아나네요.

c++ 컴파일러를 설치합니다.

 yum c++ 패키지 확인
[root@localhost ~]# yum list *c++*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.navercorp.com
 * epel: ftp.iij.ad.jp
 * extras: mirror.navercorp.com
 * updates: mirror.navercorp.com
Installed Packages
gcc-c++.x86_64                                                        4.8.5-44.el7                                                         @base
libstdc++.x86_64                                                      4.8.5-44.el7                                                         @anaconda
libstdc++-devel.x86_64                                                4.8.5-44.el7                                                         @base
..생략...
uuid-c++-devel.x86_64                                                 1.6.2-26.el7                                                         base
xmlrpc-c-c++.i686                                                     1.32.5-1905.svn2451.el7                                              base
xmlrpc-c-c++.x86_64                                                   1.32.5-1905.svn2451.el7                                              base

 gcc-c++.x86_64 패키지 설치
[root@localhost ~]# yum install gcc-c++.x86_64

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.navercorp.com
 * epel: ftp.iij.ad.jp
 * extras: mirror.navercorp.com
 * updates: mirror.navercorp.com
Resolving Dependencies
--> Running transaction check
---> Package gcc-c++.x86_64 0:4.8.5-44.el7 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-44.el7 for package: gcc-c++-4.8.5-44.el7.x86_64
--> Running transaction check
---> Package libstdc++-devel.x86_64 0:4.8.5-44.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================
 Package                                  Arch                            Version                               Repository                     Size
===============================================================================
Installing:
 gcc-c++                                  x86_64                          4.8.5-44.el7                          base                       7.2 M
Installing for dependencies:
 libstdc++-devel                          x86_64                          4.8.5-44.el7                          base                    1.5 M
Transaction Summary
===============================================================================
Install  1 Package (+1 Dependent package)

Total download size: 8.7 M
Installed size: 25 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): libstdc++-devel-4.8.5-44.el7.x86_64.rpm                                                                       | 1.5 MB  00:00:00
(2/2): gcc-c++-4.8.5-44.el7.x86_64.rpm                                                                                | 7.2 MB  00:00:01
---------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                               7.1 MB/s | 8.7 MB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libstdc++-devel-4.8.5-44.el7.x86_64                                                                                   1/2
  Installing : gcc-c++-4.8.5-44.el7.x86_64                                                                                            2/2
  Verifying  : gcc-c++-4.8.5-44.el7.x86_64                                                                                             1/2
  Verifying  : libstdc++-devel-4.8.5-44.el7.x86_64                                                                                   2/2

Installed:
  gcc-c++.x86_64 0:4.8.5-44.el7

Dependency Installed:
  libstdc++-devel.x86_64 0:4.8.5-44.el7

Complete!

 정상 설치 확인 . 버전 체크
[root@localhost ~]# g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 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.

 

컴파일 잘 되는지 확인해 봐야겠죠.

샘플 하나 만들어 테스트해볼게요.

[tmach@localhost test]$ vi hello.cpp
#include <iostream>

int main()
{
    std::cout << "Hello World~" << std::endl;
    return 0;
}

[tmach@localhost test]$ g++ hello.cpp -o hello

[tmach@localhost test]$ hello
Hello World~

 

 

감사합니다.

반응형

댓글