ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • ldd 라이브러리 참조 확인 도구
    2011. 7. 18. comments

    ldd 명령어란 프로그램 또는 공유 라이브러리가 필요로 하는 공유 라이브러리를 출력해주는 명령어이다. 

    공유라이브러리가 필요로 하는 공유 라이브러리라고 말하니 말이 뭔가 안맞는 느낌인데, 라이브러리 자체에서도 다른 라이브러리를 사용해야 되고 필요로 해야 할 때가 있다.

    예를 들어 python 같은 언어가 제공해주는 라이브러리들도 수많은 다른 라이브러리를 사용하도록 되어 있는 경우가 있다.

    역시 자세한 설명은 man을 통하여 파악할 수 있다.

    morenice@ubuntu:~$ man ldd
    LDD(1)                                                                                                                            LDD(1)
    
    NAME
           ldd - print shared library dependencies
    
    SYNOPSIS
           ldd [OPTION]...  FILE...
    
    DESCRIPTION
           ldd prints the shared libraries required by each program or shared library specified on the command line.
    
    OPTIONS
           --version
                  Print the version number of ldd.
    
           -v --verbose
                  Print all information, including e.g. symbol versioning information.
    
           -d --data-relocs
                  Perform relocations and report any missing objects (ELF only).
    
           -r --function-relocs
                  Perform relocations for both data objects and functions, and report any missing objects or functions (ELF only).
    
           -u --unused
                  Print unused direct dependencies.
    
           --help Usage information.
    
    BUGS
           ldd does not work on a.out shared libraries.
    
           ldd  does not work with some extremely old a.out programs which were built before ldd support was added to the compiler releases.
           If you use ldd on one of these programs, the program will attempt to run with argc = 0 and the results will be unpredictable.
    
    AUTHOR
           Roland McGrath and Ulrich Drepper.
    
    SEE ALSO
           ldconfig(8), ld.so(8).
    
    


    아. 윈도우에서 dependency worker와 동일하게 생각하시면 된다.
    dependecy worker에서도 프로그램과 공유 라이브러리의 참조를 확인할 때 사용하니까.

    자. 그럼 이걸 왜 사용할까???
    라이브러리의 참조를 확인하는 경우를 생각하면 된다.


    1. 개발환경이 아닌 사용자 환경에서의 비정상 작동시의 원인 파악
    2. 개발환경 변경으로 인한 개발환경 구축시 필요로 하는 라이브러리 참조 확인.


    보통 두가지로 압축이 된다.
    리눅스에서 c언어로 만든 코드들은 libc 라이브러리들을 기본적으로 참조한다.
    간단히 코드를 작성하여 libc 라이브러리를 참조하는지 확인하도록 하겠다.

    #include <stdio.h>
    #include <string.h>
    
    int main(int argc, char* argv[])
    {
      printf( "%s is run. name length %d\n", argv[0], strlen(argv[0]) );
      return 0;
    }
    

    위의 코드를 test.c 라는 파일로 만들어서 컴파일하여 test라는 바이너리를 만들었다.
    ※ 컴파일은 간단히 make test 라고 적으면 진행할 수 있다.


    그런 후에 ldd test 명령어를 통하여 해당 프로그램의 libc 라이브러리 참조를 확인할 수 있다.

    morenice@ubuntu:~$ ldd test
            linux-gate.so.1 =>  (0x00fcb000)
            libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00110000)
            /lib/ld-linux.so.2 (0x00861000)
    
     


    반응형

    댓글

Designed by Tistory.