LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   libraries (https://www.linuxquestions.org/questions/linux-software-2/libraries-89273/)

exodist 09-04-2003 01:52 PM

libraries
 
a long tiem ago I was given a command that would tell me what libraries a binary calls, you ran it in this commandline

$ command binary

that simple it would then print a list of libraries.

does anyone knwo what this command/program is?

david_ross 09-04-2003 01:56 PM

You may be talking about strace:
strace your_command

darthtux 09-04-2003 01:56 PM

ldd program

exodist 09-04-2003 02:11 PM

ldd is what I was looking for, now here is the tricky question:
lld lynx gives this:
ldd `which lynx`
libz.so.1 => /usr/lib/libz.so.1 (0x4002a000)
libncurses.so.5 => /lib/libncurses.so.5 (0x40038000)
libssl.so.0 => /usr/lib/libssl.so.0 (0x40074000)
libcrypto.so.0 => /usr/lib/libcrypto.so.0 (0x400a5000)
libc.so.6 => /lib/libc.so.6 (0x401a2000)
libdl.so.2 => /lib/libdl.so.2 (0x402d5000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

what would I do in a shell script to make that output to this:

ldd ${i}
needed command to make that go into a variable like this:
echo ${out}
libz.so.1 libncurses.so.5 libssl.so.0 libcrypto.so.0 libc.so.6 libdl.so.2 linux.so.2

basically I need to get a list of the libraries a program (${i}) needs and have that list in the format of each one next to the other in a variable (${out})

any ideas?

david_ross 09-04-2003 02:21 PM

Try this:
echo -n `ldd \`which lynx\`| cut -d"=" -f1 | awk {'print $1'}`

exodist 09-04-2003 02:28 PM

that worked great, now 2 questions

1) when I add this to a script I am working on should I give you credit by saying: "I love it, I got it at Ross?"?

2) how do I cut /lib/ld-linux.so.2 out of the end of the output :-P I am not a newbie, but in the 4 years I have used linux I have never done anything in text/string manipulation.

david_ross 09-04-2003 02:41 PM

1) Completely up to you - I ain't exactly going to prosecute :)
Clicking the Affero button is a good way to show appreciation and it helps LQ at the same time.
2) If you mean get rid of "/lib/" then you could use sed:
echo `ldd \`which lynx\`| cut -d"=" -f1 | sed {'s/\/lib\///'} | awk {'print $1'}`

exodist 09-04-2003 02:45 PM

I think I will be looking into these, sed, awk, and cut commands/programs

david_ross 09-04-2003 02:49 PM

They all have their uses - once you get used to them then it isn't too hard to see when tou use them. awk and sed can actually get quite complicated and involve large scripts in more complex cases.

exodist 09-04-2003 03:10 PM

well, actually I needed them for a script I am working on, it is a 2000 line *(so far) script that will take a directory of taballs/subdirectories, compile sourcecodes in configure/make perl, python, precompiled, then install or make packages of them using rpm, tgz, deb or a tar.bz2 with a few helpers inside. almost done, just needed this to help top it off.


All times are GMT -5. The time now is 08:07 AM.