2009년 6월 6일 토요일

gcc library 만들기


정적 라이브러리 만들기


1.Object 만들기
$ g++ -c Squawk.cpp Cat.cpp Dog.cpp Lion.cpp Car.cpp

2.라이브러리 만들기
$ ar cr libSquawk.a Squawk.o Cat.o Dog.o Car.o Lion.o

3.라이브러리 인덱스 만들기 (optional)
ranlib == ar -s와 같으며, 만들어진 index는 nm -s를 통해 확인 가능
$ ranlib libSquawk.a

정적 라이브러리 사용하기

1.컴파일
라이브러리 Header 파일 디렉토리 지정 필요
$ g++ -c -I ../CoreSquawk main.cpp

2.링크
라이브러리 및 라이브러리 디렉토리 지정 필요
$ g++ -o TestSquawk.exe main.o -L ../CoreSquawk -lSquawk

공유 라이브러리 만들기

하나 이상의 프로세스에서 사용되는 경우 메모리 양과 실행 파일 크기 줄여줌, 개발 과정 용이, 라이브러리의 변경시에도 대부분 애플리케이션 재컴파일 불필요

1.재배치가능한 Object (Position Independent Code) 만들기
$ g++ -fPIC -c Squawk.cpp Cat.cpp Dog.cpp Lion.cpp Car.cpp

2.공유 라이브러리 만들기
$ gcc -shared -o libSquawk.so Squawk.o Cat.o Dog.o Car.o Lion.o

공유 라이브러리 사용하기

1.컴파일 라이브러리 Header 파일 디렉토리 지정 필요
$ g++ -c -I ../CoreSquawk main.cpp

2.링크 라이브러리 및 라이브러리 디렉토리 지정 필요
$ g++ -o TestSquawk.exe main.o -L ../CoreSquawk -lSquawk

꼭 정적인 라이브러리를 링크 하고자 할 때
$ g++ -o TestSquawk.exe main.o ../CoreSquawk/libSquawk.a

ldd 명령: 실행 프로그램이 사용하는 공유 라이브러리 나열
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/user/CoreSquawk
$ ldd TestSquawk.exe

참고자료 :
윈도우에서 유닉스로 이식하기 http://www.ibm.com/developerworks/kr/library/au-porting/index.html

git 사용 하기

git 사이트 : http://www.git-scm.com/

git 설치 (ubuntu)
$ sudo apt-get install git-core
$ sudo apt-get install gitk (for graphical version history)
$ sudo apt-get meld (for merge)

configuration 정보 :
.git/config, ~/.gitconfig(--global), /etc/gitconfig(--system)
참고 : http://www.kernel.org/pub/software/scm/git/docs/git-config.html
$ git config --global user.name "PoongCha"
$ git config --global user.email icharm9@gmail.com

작업 디렉토리 초기화 (.git 디렉토리를 만듦)
$ cd Git (작업 디렉토리)
$ git init

임시 영역 "index"에 저장
$ tar xzf Squawk.tar.gz
$ git add Squawk/

리파지토리 "stage(--cached)"에 저장
$ git commit -m "Initial Importing"
(use "git rm --cached ..." to unstage)

새 파일을 "index"에 추가
$ git add Makefile

새 파일을 리파지토리 "stage(--cached)"에 저장
$ git commit
(use "git reset HEAD ..." to unstage)

파일을 수정하기
$ vi Makefile
$ git diff Makefile (작업디렉토리와 "index" 비교)

수정한 파일을 "index"에 저장
$ git add Makefile

수정한 파일을 "stage(--cached)"에 저장
$ git diff --cached Makefile (option)
$ git status Makefile (option)
$ git commit

수정된 파일들을 자동으로 인식해서 index에 넣고 커밋까지 한꺼번에 하는 방법
$ git commit -a

프로젝트 히스토리
$ git log (주석을 리스트)
$ git log -p (주석과 함께 변경된 내용을 리스트)
$ git log --stat (주석과 함께 파일스텝라인 리스트)

Branch 만들기 및 Branch에서의 수정 작업
$ git branch translation_KR (translation_KR Branch에서 작업하기)
$ git branch (branch 리스트)
$ git checkout translation_KR (working branch를 translation_KR로 switching)
$ vi CoreSquawk/Dog.cpp
$ git commit -a

"master" Branch에서 수정
$ git checkout master (master Branch에서 작업하기)
$ vi CoreSquawk/Dog.cpp
$ git commit -a

Branch 작업을 "master" Branch로 merge 하기
$ git config --global mergetool.keepBackup false
(base,remote,local backup파일 보관여부)
$ git merge translation_KR
Auto-merged Squawk/CoreSquawk/Dog.cpp
CONFLICT (content): Merge conflict in Squawk/CoreSquawk/Dog.cpp
Automatic merge failed; fix conflicts and then commit the result.
$ git diff
master(LOCAL):Squawk/CoreSquawk/Dog.cpp
<<<<<<< bow_wow = "Grrrrrrr"> bow_wow = "멍멍멍">>>>>>>
translation_KR(REMOTE):Squawk/CoreSquawk/Dog.cpp

meld GUI를 이용한 merge 작업
$ git mergetool -t meld
참고 : Comparing and merging files with Meld http://www.linux.com/archive/feature/61372
$ git commit -a
$ gitk (for project's graphical history browser)
$ git branch -d translation_KR (after merge)
$ git branch -D translation_KR (remove branch anyway)

다른 작업 디렉토리 또는 다른 작업자가 작업하기
$ git clone Git Git2 (will create Git2 directory and copy files & project histories)
$ cd Git2 (작업 디렉토리)
$ vi Squawk/CoreSquawk/Cat.cpp
$ git commit -a
$ gitk

다른 작업 디렉토리 또는 다른 작업자 결과를 가져와서 merge하기
$ git pull ../Git2 master (다른 작업 영역의 master 브랜치를 현재 작업 브랜치로 가져옴)
$ gitk



Mercurial의 Workflow와의 비교

cygwin 한글 입출력 설정

$ vi .bashrc...
alias ls='ls -hF --color=auto --show-control-char'
alias dir='ls --color=auto --format=vertical --show-control-char'
...

$ vi .inputrc
...
# Allow 8-bit input/output
set meta-flag on
set convert-meta off
set input-meta on
set output-meta on

...