GNU Binutils
GNU 바이너리 유틸리티 또는 GNU Binutils는 여러 종류의 오브젝트 파일 형식들을 조작하기 위한 프로그래밍 도구 모음이다. 현재 버전은 시그너스 솔루션즈의 프로그래머들이 BFD 라이브러리를 이용해 처음부터 만든 것이다. 이는 일반적으로 GCC, make, GDB와 함께 사용된다.
동적 라이브러리(so)와 정적 라이브러리(a)
static library
컴파일시 적용된다. 확장자는 .a
이다. 컴파일 과정에서 공유 라이브러리 루틴을 사용하지 않고, 프로그램에서 프로그램 소스 상 라이브러리 루틴의 복사본을 갖도록 컴파일.
만드는 방법은 아래와 같다.
gcc -c source1.c source2.c # Object 코드 만들
ar r libStatic.a source1.o source2.o # 라이브러리 만들기
ranlib libStatic.a # 라이브러리 자체 루틴 정보추가 과정
ar rs libStatic.a source1.o source2.o # 라이브러리 만들기 + 인덱스 만들기 통합 명령
# 이후 각 루틴의 Signature가 exturn 형태로 선언된 헤더파일을 만든다.
gcc -I ../include -L ../lib -o main main.c -lstatic # -lstatic: 정적 라이브러리 링크
참고로 꼭 정적인 라이브러리를 링크 시키고자 할때는 아래와 같이 .a
파일을 추가하면 된다.
Dynamic library
개발이 용이하고 확장자는 .so
이다. 라이브러리 변경시 재 컴파일 불필요. 하나 이상의 프로세스에서 사용시, 메모리 양과 실행 파일 크기를 줄여줌.
만드는 방법은 아래와 같다.
gcc -c -fpic source1.c source2.c # 재배치 코드 생성. (-fpic, -fPIC: 공유를 위한 위치 독립적 생성)
gcc -shared -o libDynamic.so source1.o source2.o # 공유 라이브러리 생성. (인덱스 과정 불필요)
gcc -I ../include -L ../lib -o main main.c -ldynamic # 정적 라이브러리 생성과 동일. (*.a 와 *.so 가 있다면 *.so 선택적 수행)
(참고로 -fpic
와 -fPIC
옵션은 다르다. 자세한 내용은 여기를 참조)
유용한 명령 또는 사용법
라이브러리 경로 설정
라이브러리가 위치하는 위치가 다수 존재할 경우 아래와 같이 미리 설정할 수 있다.
$ cd /etc/local/lib
$ vi /etc/ld.so.conf
$ include /etc/ld.so.conf.d/*.conf # /etc/ld.so.conf.d 의 모든 conf 를 include
Project List
- ld - the GNU linker.
- as - the GNU assembler.
- addr2line - Converts addresses into filenames and line numbers.
- ar - A utility for creating, modifying and extracting from archives.
- c++filt - Filter to demangle encoded C++ symbols.
- dlltool - Creates files for building and using DLLs.
- gold - A new, faster, ELF only linker, still in beta test.
- gprof - Displays profiling information.
- nlmconv - Converts object code into an NLM.
- nm - Lists symbols from object files.
- objcopy - Copies and translates object files.
- objdump - Displays information from object files.
- ranlib - Generates an index to the contents of an archive.
- readelf - Displays information from any ELF format object file.
- size - Lists the section sizes of an object or archive file.
- strings - Lists printable strings from files.
- strip - Discards symbols.
- windmc - A Windows compatible message compiler.
- windres - A compiler for Windows resource files.
- ltrace - A library call tracer
See also
Favorite site
- GNU binutils web site
- Wikipedia (en) GNU Binutils에 대한 설명
- [추천] System section web site (Binary Hacks: Binutils) 1
- BinUtil 에 대해서 상세히 알아보자
- [추천] Using static and shared libraries across platforms 2