카테고리

asm (27) bootloader_x86_grub (1) C (92) compile (11) config (76) CPP (13) CSS (1) debugging (7) gimp (1) Go (1) html (1) Java (1) JavaScript (1) kernel (19) LibreOffice (3) Linux system progamming (21) MFC (1) opencv (4) OpenGL (1) PHP (1) Python (4) qemu (29) shell (3) socket (7) troubleshooting (2) ubuntu18.04 (2) windows (1)

2019/01/03

Ubuntu 18.04 64 비트 GCC 8.2 버전 컴파일

GCC 빌드하기
Ubuntu 18.04 64 비트 GCC 8.2 버전 컴파일

업데이트
sudo apt-get update
sudo apt-get upgrade

코드 다운로드
cd ~
wget https://ftpmirror.gnu.org/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz
tar xf gcc-8.2.0.tar.gz
cd gcc-8.2.0
contrib/download_prerequisites

환경 구성
cd ~
mkdir build && cd build
../gcc-8.2.0/configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --prefix=/usr/local/gcc-8.2 --enable-checking=release --enable-languages=c,c++,fortran --disable-multilib --program-suffix=-8.2

적용 -j 8 cpu 코어 확인
make -j 8

설치
sudo make install

실행 경로 추가
export export PATH=/usr/local/gcc-8.2/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/gcc-8.2/lib64:$LD_LIBRARY_PATH

.bashrc 추가
cd ~
vi .bashrc
export export PATH=/usr/local/gcc-8.2/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/gcc-8.2/lib64:$LD_LIBRARY_PATH

// C++14 일반화 된 람다(매개변수 유형 auto 사용)
// https://solarianprogrammer.com/2014/08/21/cpp-14-auto-tutorial/
#include <iostream>
int main() {
    std::cout << [](auto a, auto b) { return a + b; } (5, 6) << std::endl;
    std::cout << [](auto a, auto b) { return a + b; } (5.23, 6.45) << std::endl;
    return 0;
}

컴파일
g++-8.2 -Wall -pedantic test_lambda.cpp -o test_lambda
./test_lambda

static_assert 수정 예제 테스트
// https://solarianprogrammer.com/2014/08/21/cpp-14-auto-tutorial/
#include <type_traits>
#include <iostream>
struct A {
int foo;
};

struct B {
int foo = 0;
};

template <typename T>
void print(const T& a){
static_assert(std::is_pod<T>::value);
std::cout << a.foo << '\n';
}

int main() {
A x{1};
B y{2};
B z;

print<A>(x);
print<B>(y);
print<B>(z);

return 0;
}

컴파일
g++-8.2 -std=c++17 -Wall -pedantic test_assert.cpp -o test_assert
 test_assert.cpp: In instantiation of ‘void print(const T&) [with T = B]’:
 test_assert.cpp:24:15:   required from here
 test_assert.cpp:14:5: error: static assertion failed
     static_assert(std::is_pod<T>::value);
     ^~~~~~~~~~~~~

Fortran 프로그래머라면 gfortran-8.2와 병행 하여 다음과 같은 Fortran 2008 기능 중 일부를 사용할 수 있음.

integer,parameter::mm=100000
real::a(mm), b(mm)
real::fact=0.5

! initialize the arrays
! ...

do concurrent (i = 1 : mm)
a(i) = a(i) + b(i)
enddo

end

컴파일 테스트
gfortran-8.2 test_concurrent_do.f90 -o test_concurrent_do
./test_concurrent_do

댓글 없음:

댓글 쓰기