GCC - 윈디하나의 솔라나라
|
# wget --no-check-certificate https://gmplib.org/download/gmp/gmp-6.1.1.tar.lz # tar -xv --lzip -f gmp-6.1.1.tar.lz 1) # cd gmp-6.1.1 # ABI="32" CFLAGS="-m32" ./configure \ --enable-cxx \ --prefix=/usr/local 2) # dmake # make check # make install1) lz 파일이 풀리지 않을 경우 lzip(1)이 설치되어있는지 확인해보자. 없는 경우 윈디하나의 솔라나라: 아카이버 및 컴프레서을 참고해 설치하자.
ABI="64" CFLAGS="-m64"
를 사용한다.
# wget http://www.mpfr.org/mpfr-current/mpfr-3.1.4.tar.bz2
# tar xvfj mpfr-3.1.4.tar.bz2
# cd mpfr-3.1.4
# CFLAGS="-m32" ./configure \
--with-gmp=/usr/local \
--enable-thread-safe \
--prefix=/usr/local 1)
# dmake
# make check
# make install
1) 64비트로 컴파일 할 경우 CFLAGS="-m64"
를 사용한다.
# wget http://www.multiprecision.org/mpc/download/mpc-1.0.3.tar.gz
# tar xvfz mpc-1.0.3.tar.gz
# cd mpc-1.0.3
# ABI="32" CFLAGS="-m32" ./configure \
--with-gmp=/usr/local \
--with-mpfr=/usr/local \
--prefix=/usr/local 1)
# make
# make install
1) 64비트로 컴파일 할 경우 ABI="64" CFLAGS="-m64"
를 사용한다.
# wget http://ftp.kaist.ac.kr/gnu/gnu/binutils/binutils-2.25.tar.bz2 # tar xvfj binutils-2.25.tar.bz2 # cd binutils-2.25 # ./configure --prefix=/usr/local/gcc # vi binutils/dwarf.c # 298 라인 int dummy [sizeof (VAL) < (AMOUNT) ? 1 : 1] ATTRIBUTE_UNUSED ; \ # /usr/sfw/bin/gmake # /usr/sfw/bin/gmake install # rm /usr/local/gcc/i386-pc-solaris2.1?/bin/ld* # rm /usr/local/gcc/bin/ld*
root@wl ~/src # wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-6.1.0/gcc-6.1.0.tar.bz2 root@wl ~/src # tar xvfj gcc-6.1.0.tar.bz2 root@wl ~/src # cd gcc-6.1.0 root@wl ~/src/gcc-6.1.0 # mkdir objdir root@wl ~/src/gcc-6.1.0 # cd objdir root@wl ~/src/gcc-6.1.0/objdir # ../configure \ CC=/usr/sfw/bin/gcc CXX=/usr/sfw/bin/g++ \ CFLAGS="-m32" CXXFLAGS="-m32" \ --prefix=/usr/local/gcc \ --with-as=/usr/local/gcc/bin/as \ --with-ld=/usr/ccs/bin/ld \ --with-gmp=/usr/local \ --with-mpfr=/usr/local \ --with-mpc=/usr/local \ --enable-languages=c,c++,fortran,objc root@wl ~/src/gcc-6.1.0/objdir # LANG=C LD_LIBRARY_PATH=/usr/local/gcc/lib:$LD_LIBRARY_PATH /usr/sfw/bin/gmake -j 4 ... ... ... root@wl ~/src/gcc-6.1.0/objdir # gmake install
root@wl ~ # vi /etc/profile ... PATH=/usr/local/gcc/bin:$PATH; export PATH CC=/usr/local/gcc/bin/gcc; export CC CXX=/usr/local/gcc/bin/g++; export CXX root@wl ~ # . /etc/profile root@wl ~ # gcc -v Using built-in specs. COLLECT_GCC=/usr/local/gcc/bin/gcc COLLECT_LTO_WRAPPER=/usr/local/gcc/libexec/gcc/i386-pc-solaris2.10/4.8.2/lto-wrapper Target: i386-pc-solaris2.10 Configured with: ../configure ... Thread model: posix gcc version 4.8.2 (GCC) root@wl ~ #
/usr/local/gcc
에 설치했기 때문에 crle(1)을 사용해 라이브러리 경로를 변경해야 한다.
crle -l
의 인자를 잘못 입력하면, 시스템을 망가뜨릴 수 있다. (프로그램 실행 불가) 원래대로 복구하려면 /var/ld/ld.config
, /var/ld/64/ld.config
를 삭제해야 하는데 경우에 따라 rm(1)조차 실행 안될 수 있다. 이런 경우 싱글모드를 사용하자. 싱글모드에 대한 설명은 윈디하나의 솔라나라: 싱글 모드을 참고하자.root@wl ~ # crle 기본 구성 파일 (/var/ld/ld.config)을(를) 찾지 못함 Platform: 32-bit LSB 80386 기본 라이브러리 경로 (ELF): /lib:/usr/lib (시스템 기본값) 인증된 디렉토리 (ELF): /lib/secure:/usr/lib/secure (시스템 기본값) root@wl ~ # crle -64 기본 구성 파일 (/var/ld/64/ld.config)을(를) 찾지 못함 Platform: 64-bit LSB AMD64 기본 라이브러리 경로 (ELF): /lib/64:/usr/lib/64 (시스템 기본값) 인증된 디렉토리 (ELF): /lib/secure/64:/usr/lib/secure/64 (시스템 기본값) root@wl ~ # crle -u -l /lib:/usr/lib:/usr/local/gcc/lib 1) root@wl ~ # crle -64 -l /lib/64:/usr/lib/64:/usr/local/gcc/lib/amd64 1) root@wl ~ # crle Configuration file [version 4]: /var/ld/ld.config Platform: 32-bit LSB 80386 기본 라이브러리 경로 (ELF): /lib:/usr/lib:/usr/local/gcc/lib 인증된 디렉토리 (ELF): /lib/secure:/usr/lib/secure (시스템 기본값) ... root@wl ~ # crle -64 Configuration file [version 4]: /var/ld/64/ld.config Platform: 64-bit LSB AMD64 기본 라이브러리 경로 (ELF): /lib/64:/usr/lib/64:/usr/local/gcc/lib/amd64 인증된 디렉토리 (ELF): /lib/secure/64:/usr/lib/secure/64 (시스템 기본값) ...1) 시스템 기본값에서
/usr/local/gcc/lib
, /usr/local/gcc/lib/amd64
만 추가해준다. 경로가 잘못되면 시스템이 손상될 수 있으므로 주의한다.
root@wl ~ # which gcc /usr/local/gcc/bin/gcc root@wl ~ # wget http://www.solanara.net/contents/includes/helloworld.c root@wl ~ # wget http://www.solanara.net/contents/includes/helloworld.cc
helloworld.c | (203 바이트) |
/* Print [Hello, World!] WindyHana's Solanara http://www.solanara.net/ cc -o helloworld helloworld.c */ #include <stdio.h> int main(int argc, char *argv[]) { printf("Hello, World!\n"); return 0; }
helloworld.cc | (824 바이트) |
/* Print [Hello, World!] WindyHana's Solanara http://www.solanara.net/ CC -o helloworld helloworld.cc */ #include <iostream> #include <string> using namespace std; class CGreeter { private: string name; public: CGreeter(string name); void printgreet(); }; CGreeter::CGreeter(string iname) { this->name = iname; // 첫글자 대문자화 함수를 제공하지 않음 } void CGreeter::printgreet() { cout << "Hello " << this->name << "!" << endl; } int main(int argc, char *argv[]) { CGreeter* greet = new CGreeter("World"); greet->printgreet(); delete greet; return 0; } #if __cplusplus >= 201402L __attribute__((weak)) void operator delete(void * ptr, std::size_t) { ::operator delete(ptr); } __attribute__((weak)) void operator delete[](void * ptr, std::size_t) { ::operator delete(ptr); } #endif
root@wl ~ # gcc -o helloworld helloworld.c root@wl ~ # ./helloworld Hello, World! root@wl ~ # g++ -o helloworld helloworld.cc root@wl ~ # ./helloworld Hello, World!
root@wl ~ # gcc -m64 -o helloworld helloworld.c root@wl ~ # ./helloworld Hello, World! root@wl ~ # g++ -m64 -o helloworld helloworld.cc root@wl ~ # ./helloworld Hello, World!
-static-libgcc
와 -static-libstdc++ 옵션을 주면, libstdc++.so 와 libgcc_s.so 를 사용하지 않도록 정적(static)으로 컴파일 할 수 있다. 하지만 ABI나 dlopen(3C)를 쓸 때 문제가 생길 수 있는 것으로 알려져 있어 권장하지는 않는다.
root@wl ~ # g++ -o helloworld helloworld.cc root@wl ~ # ls -al helloworld -rwxr-xr-x 1 root root 10172 1월 10일 18:00 helloworld root@wl ~ # ldd helloworld libstdc++.so.6 => /usr/local/gcc/lib/libstdc++.so.6 libm.so.2 => /usr/lib/libm.so.2 libgcc_s.so.1 => /usr/local/gcc/lib/libgcc_s.so.1 libc.so.1 => /usr/lib/libc.so.1 root@wl ~ # g++ -static-libgcc -static-libstdc++ -o helloworld helloworld.cc root@wl ~ # ls -al helloworld -rwxr-xr-x 1 root root 3576460 1월 10일 18:00 helloworld root@wl ~ # ldd helloworld libm.so.2 => /usr/lib/libm.so.2 libc.so.1 => /usr/lib/libc.so.1
이 섹션은 곧 보강될 예정입니다.
모든 옵션은 GCC Command Options - Option Summary를 참고하자.-g: 실행파일에 디버깅 정보 넣음 -O3: 옵티마이저 레벨 3
windy@wl ~/src $ wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-11.2.0/gcc-11.2.0.tar.xz windy@wl ~/src $ /usr/gnu/bin/tar xvfJ gcc-11.2.0.tar.xz windy@wl ~/src $ cd gcc-11.2.0 windy@wl ~/src/gcc-11.2.0 $ mkdir build windy@wl ~/src/gcc-11.2.0 $ cd build windy@wl ~/src/gcc-11.2.0/build $ ../configure \ --prefix=/usr/local/gcc \ --enable-languages=c,c++,fortran,objc \ --enable-shared \ --enable-initfini-array \ --with-system-zlib \ --with-gmp-include=/usr/include \ --with-mpfr-include=/usr/include \ --without-gnu-ld \ --with-ld=/usr/bin/ld \ --with-gnu-as \ --with-as=/usr/gnu/bin/as \ --disable-rpath \ --disable-bootstrap 'BOOT_CFLAGS=-g -O2' \ x86_64-pc-solaris2.11 windy@wl ~/src/gcc-11.2.0/build $ /usr/gnu/bin/make windy@wl ~/src/gcc-11.2.0/build $ sudo /usr/gnu/bin/make install
windy@wl ~ $ /usr/local/gcc/bin/gcc -v Using built-in specs. COLLECT_GCC=./gcc COLLECT_LTO_WRAPPER=/usr/local/gcc/libexec/gcc/x86_64-pc-solaris2.11/11.2.0/lto-wrapper Target: x86_64-pc-solaris2.11 Configured with: ../configure --prefix=/usr/local/gcc --enable-languages=c,c++,fortran,objc --enable-shared --enable-initfini-array --with-system-zlib --with-gmp-include=/usr/include --with-mpfr-include=/usr/include --without-gnu-ld --with-ld=/usr/bin/ld --with-gnu-as --with-as=/usr/gnu/bin/as --disable-rpath --disable-bootstrap 'BOOT_CFLAGS=-g -O2' x86_64-pc-solaris2.11 Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.2.0 (GCC)
/usr/local/gcc/lib
(32bit)와 /usr/local/gcc/lib/amd64
(64bit) 에 설치된다. 이 경로를 라이브러리 경로에 넣어야 한다. 라이브러리 경로에 넣는 방법은 아래항목중 한가지를 사용하면 된다.
LD_LIBRARY_PATH
변수에 지정-RLIBDIR
플래그 지정RSS ATOM XHTML 5 CSS3 |
Copyright © 2004-2025 Jo HoSeok. All rights reserved. |