Results 1 to 1 of 1

Thread: question regarding LD_PRELOAD

  1. #1
    Join Date
    Aug 2012
    Beans
    597

    question regarding LD_PRELOAD

    Hello,
    I was reading about LD_PRELOAD and LD_LIBRARY_PATH and came to know that on doing export LD_PRELOAD=/home/path/to/libmylib.so, it loads the libmylib.so before loading any other library.

    I have three questions:
    1.How is -L different from LD_PRELOAD and LD_LIBRARY_PATH ?
    Probable answer :-L links at link time while LD_PRELOAD and LD_LIBRARY_PATH at run time. I just need some confirmation on this.

    2.Can I say that doing
    LD_PRELOAD=/path/required/libmylib.so ./a.out is same as
    copying the required .so to one of the folders mentioned in LD_LIBRARY_PATH ? that is,
    Code:
        
    $cp libmylib.so /home/mypath/library
    $gcc -Wall -L/home/mypath/library -lmylib -o exe
    $export LD_LIBRARY_PATH=/home/mypath/library
    $./a.out
    3.In the LD_LIBRARY_PATH way of doing things, in the link stage itself,($gcc -Wall -L/home/mypath/library -lmylib -o exe), you are mentioning that the shared object called libmylib resides in /home/mypath/library, and then the exe is created.
    Then why can't the exe run taking the shared object from here. Why do we again have to do $export LD_LIBRARY_PATH=/home/mypath/library before running the executable ?

    Thanks.
    Last edited by IAMTubby; January 16th, 2013 at 02:53 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •