1. AIX에서의 shared library와 static library compile 방법
가. source file 준비
1) app.c
int main()
{
func();
return 0;
}
2) test.c
#include
void func()
{
printf("Hello World!!\n");
}
나. static library로 compile
cc -c test.c
cc -c app.c
ar -cr libtest.a test.o
cc -o app app.o -L. -ltest
다. dynamic library로 compile
xlc -c test.c
xlc -G -bM:SRE -o libtest.so test.o
ar -cr libtest.a libtest.so
xlC -o app app.c -brtl -L. -ltest
2. 만들어진 application에 대해, dynamic과 static의 구동 차이점 알아보기
가. static library : 외부라이브러리를 전혀 참조하지 않음
truss -u libtest.a::* app
execve("./app", 0x2FF22450, 0x2000FB38) argc: 1
kioctl(1, 22528, 0x0000000000000000, 0x0000000000000000) = 0
Hello World!!
kwrite(1, " H e l l o W o r l d !".., 14) = 14
kfcntl(1, F_GETFL, 0x0000000000000000) = 2
kfcntl(2, F_GETFL, 0x09001000A009B308) = 2
_exit(0)
나. dynamic library : 저 아래에 libtest.a의 func()을 runtime에 호출
truss -u libtest.a::* app
execve("./app", 0x2FF227D4, 0x2000FB38) argc: 1
sbrk(0x0000000000000000) = 0x0000000010000AF8
vmgetinfo(0x0FFFFFFFFFFFEFA0, 7, 16) = 0
sbrk(0x0000000000000000) = 0x0000000010000AF8
sbrk(0x0000000000000008) = 0x0000000010000AF8
__libc_sbrk(0x0000000000010020) = 0x0000000010000B00
kfcntl(0, F_GETFL, 0x0000000000000000) = 2
kfcntl(1, F_GETFL, 0x0000000000000000) = 2
kfcntl(2, F_GETFL, 0x0000000000000000) = 2
kfcntl(2, F_GETFL, 0x0000000000000000) = 2
->libtest.a:func()
kioctl(1, 22528, 0x0000000000000000, 0x0000000000000000) = 0
Hello World!!
kwrite(1, " H e l l o W o r l d !".., 14) = 14
<-libtest.a:func() = e 0.000000
kfcntl(1, F_GETFL, 0x0000000000000000) = 2
kfcntl(2, F_GETFL, 0x09001000A009B308) = 2
_exit(0)
다. dump command로 확인하기
dynamic의 경우, 아래와 같이 import section에 해당 library가 포함되어 있음
dump -Hv app
... 중략
***Import File Strings***INDEX PATH BASE MEMBER
0 .:/usr/lpp/xlopt:/usr/vacpp/lib:/usr/lib:/lib
1 libtest.a libtest.so
2 libC.a shr_64.o
3 libc.a shr_64.o
가. source file 준비
1) app.c
int main()
{
func();
return 0;
}
2) test.c
#include
void func()
{
printf("Hello World!!\n");
}
나. static library로 compile
cc -c test.c
cc -c app.c
ar -cr libtest.a test.o
cc -o app app.o -L. -ltest
다. dynamic library로 compile
xlc -c test.c
xlc -G -bM:SRE -o libtest.so test.o
ar -cr libtest.a libtest.so
xlC -o app app.c -brtl -L. -ltest
2. 만들어진 application에 대해, dynamic과 static의 구동 차이점 알아보기
가. static library : 외부라이브러리를 전혀 참조하지 않음
truss -u libtest.a::* app
execve("./app", 0x2FF22450, 0x2000FB38) argc: 1
kioctl(1, 22528, 0x0000000000000000, 0x0000000000000000) = 0
Hello World!!
kwrite(1, " H e l l o W o r l d !".., 14) = 14
kfcntl(1, F_GETFL, 0x0000000000000000) = 2
kfcntl(2, F_GETFL, 0x09001000A009B308) = 2
_exit(0)
나. dynamic library : 저 아래에 libtest.a의 func()을 runtime에 호출
truss -u libtest.a::* app
execve("./app", 0x2FF227D4, 0x2000FB38) argc: 1
sbrk(0x0000000000000000) = 0x0000000010000AF8
vmgetinfo(0x0FFFFFFFFFFFEFA0, 7, 16) = 0
sbrk(0x0000000000000000) = 0x0000000010000AF8
sbrk(0x0000000000000008) = 0x0000000010000AF8
__libc_sbrk(0x0000000000010020) = 0x0000000010000B00
kfcntl(0, F_GETFL, 0x0000000000000000) = 2
kfcntl(1, F_GETFL, 0x0000000000000000) = 2
kfcntl(2, F_GETFL, 0x0000000000000000) = 2
kfcntl(2, F_GETFL, 0x0000000000000000) = 2
->libtest.a:func()
kioctl(1, 22528, 0x0000000000000000, 0x0000000000000000) = 0
Hello World!!
kwrite(1, " H e l l o W o r l d !".., 14) = 14
<-libtest.a:func() = e 0.000000
kfcntl(1, F_GETFL, 0x0000000000000000) = 2
kfcntl(2, F_GETFL, 0x09001000A009B308) = 2
_exit(0)
다. dump command로 확인하기
dynamic의 경우, 아래와 같이 import section에 해당 library가 포함되어 있음
dump -Hv app
... 중략
***Import File Strings***INDEX PATH BASE MEMBER
0 .:/usr/lpp/xlopt:/usr/vacpp/lib:/usr/lib:/lib
1 libtest.a libtest.so
2 libC.a shr_64.o
3 libc.a shr_64.o
'프로그램언어 > C/C++' 카테고리의 다른 글
Pthread API Reference (1) | 2012.03.24 |
---|---|
유용하게 사용하는 매크로 함수 (0) | 2012.03.24 |
POSIX 와 Thread-safety (0) | 2012.03.24 |
GCC 사용법 (0) | 2012.03.24 |
xlC 컴파일 옵션 - AIX (0) | 2012.03.24 |