본문 바로가기

프로그래밍/general programming

[GNU autotools] libtool을 이용한 shared library 만들기

이전글에서 autotools를 이용한 Project를 만들어 봤습니다.

2011/03/07 - [OS & Programming/general Programming] - [GNU autotools] 를 이용한 간단한 Project만들기



이번에는 libtool을 이용하여 shared library를 만들어보도록 하겠습니다.

 우선 configure.ac 파일에 libtool 관련 설정을 넣습니다.

#AC_PROG_RANLIB                #삭제

LT_INIT( [dlopen] )                 #libtool 초기화 

lib/Makefile.am 파일을 수정합니다.

lib_LTLIBRARIES = libhello.la          #libhello.a -> libhello.la 로 수정


autoreconf -i 를 실행하여 재 구성합니다.

$ autoreconf -i

libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.ac and
libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.
libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
libtoolize: `AC_PROG_RANLIB' is rendered obsolete by `LT_INIT'
 
configure를 실행하고 make install 해봅니다.

$ ./configure --prefix=/home/sekim/drill/install 
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
........
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: creating lib/Makefile
config.status: creating src/Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing libtool commands
config.status: executing depfiles commands


$ make install
Making install in lib
........
----------------------------------------------------------------------
Libraries have been installed in:
   /home/sekim/drill/install/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
make[2]: `install-data-am'를 위해 할 일이 없습니다
............
make[1]: Leaving directory `/home/sekim/drill/autotools'

설치 디렉토리로 이동후 ldd로 실행파일을 확인, 실행해 봅니다.

$ ldd hello

linux-gate.so.1 =>  (0x00d42000)

libhello.so.0 => /home/sekim/drill/install/lib/libhello.so.0 (0x00ad5000)

libc.so.6 => /lib/libc.so.6 (0x00110000)

/lib/ld-linux.so.2 (0x00d93000)

$ ./hello

hello main

Hello world. ate_hello 1.0 


혹시 실행이 되지 않는 경우는 LD_LIBRARY_PATH에 library path를 추가해주면 실행이 되겠습니다.

이상이 libtool을 이용한 shared library 생성이 추가된 Project였습니다.