Linux check which libraries

Viewing Linux Library / Executable version info

In Windows, EXE and DLL have version info, including at least the following fields:

  1. file version
  2. product version
  3. internal name
  4. product name
  5. copyright

In Linux Library / Executable:

  • Which fields are present?
  • How to view such info?
  • What tools/libraries to read?

4 Answers 4

The version info in not explicitly stored in an ELF file. What you have in there is the name of the library, the soname , which includes the major version. The full version is usually stored as a part of the library file name.

If you have library, say libtest.so , then you usually have:

  • libtest.so.1.0.1 — The library file itself, containing the full version
  • libtest.so.1 — Symlink to libtest.so.1.0.1 , having the same name as soname
  • libtest.so — Symlink to libtest.so.1 used for linking.

In the library file libtest.so.1.0.1 , there will be an entry called SONAME in dynamic section, that will say this library is called libtest.so.1 . When you link a program against this library, the linked program will store the soname of the library under NEEDED entry in the dynamic section.

If you want to verify, what exactly is in which ELF file, you can try to run:

where elffile can be either an library of an executable.

If you simply want to get the library version, you can play with:

AFAIK, there’s no such info (at least not by default) in executable files.

Or you can rely on the program itself or your packaging system, as Rahul Patil wrote.

Источник

How to check what shared libraries are loaded at run time for a given process?

Is there a way to check which libraries is a running process using?

To be more specific, if a program loads some shared libraries using dlopen, then readelf or ldd is not going to show it. Is it possible at all to get that information from a running process? If yes, how?

Читайте также:  Sony picture package для windows

8 Answers 8

Other people are on the right track. Here are a couple ways.

Both of these assume that shared libraries have «.so» somewhere in their paths, but you can modify that. The first one gives fairly pretty output as just a list of libraries, one per line. The second one will keep on listing libraries as they are opened, so that’s nice.

And of course lsof .

May be lsof — the swiss army knife of linux will help?

edit: to run, lsof -p

, lists all sorts of useful information, for example, if the process is java, lists all the open jars — very cool.

Actually, you can do this in your code in the following way:

The link_map structure contains at least the base address and the absolute file name. It’s the structure that is actually returned by dlopen() with non-NULL first argument. For more details see here.

ltrace seems to be your friend.

From ltrace manual:

ltrace is a program that simply runs the specified command until it exits. It intercepts and records the dynamic library calls which are called by the executed process and the signals which are received by that process. It can also intercept and print the system calls exe‐ cuted by the program.

Источник

Check which library compiled in linux

I want to compile a C file with gcc , to embedded arm that is running Gnu/Linux .

How can I known which function/header files that I need to compile statically, and which dynamically?(I don’t want to compile all of the headers file statically )

Is there any command that I can use?

For example I include stdio.h to use printf , is there any way to know if I must compile it statically?

1 Answer 1

You’ll need to know which dynamic libraries will be available on your target system and which are not.

For example, on my system stdio.h is one of the include files of package libc6-dev (Debian package naming conventions), and the corresponding dynamic library is libc.so.6 which is a symbolic link to libc-2.24.so . This is the GNU C Library, which is the basic building block of nearly all programs, so it would be quite unusual for your ARM system to not have it (or some equivalent of it) available as a dynamic library: since it is so universally used and fairly large, having it as a dynamic library makes very much sense.

Читайте также:  Как отключить визуализацию windows 10

(Also, GNU C Library itself uses dynamic linking for features like configurable name resolution functions: /etc/nsswitch.conf tells the C library which libnss_*.so libraries to load at run-time, so linking the GNU C Library fully statically to your program would be exceptionally tricky.)

If your embedded ARM system does not have a specific lib*.so file for a specific library installed on it, and you still wish to use that library in your program, then you must link that library statically. And to do that in a cross-compilation situation, you must have the corresponding ARM version of the lib*.a file of that library on the system you’re cross-compiling your program.

Although a library’s header files ( *.h ) might well be the same for all architectures the library is compilable in, the *.so and *.a files won’t be: since the *.so and *.a files both contain executable code, they are specific for each processor architecture. So if you are cross-compiling for ARM on a x86_64 system, having the x86_64 version of some library’s lib*.a file available won’t allow you to cross-compile an ARM program using that library statically compiled: you will need the ARM lib*.a for that library.

Источник

How to check if a library is installed?

In Linux, how do I check if a library is installed or not? (from the command line of course).

In my specific case now, I want to check whether libjpeg is installed.

9 Answers 9

To do this in a distro-independent* fashion you can use ldconfig with grep, like this:

If libjpeg is not installed, there will be no output. If it is installed, you will get a line for each version available.

Replace libjpeg by any library you want, and you have a generic, distro-independent* way of checking for library availability.

If for some reason the path to ldconfig is not set, you can try to invoke it using its full path, usually /sbin/ldconfig .

**99% of the times*

You can check with the package manager of your distribution (aptitude, yum, . ) but as you did not give your distribution I can’t give you the right command.

Читайте также:  Qemu uefi windows 10

Another way can be to run gcc -ljpeg , if you get ‘ld: library not found for -ljpeg’ it means that gcc has not found the library (but it don’t mean that it’s not installed), if you get something like ‘Undefined symbols: «_main», referenced from: . ‘ it means that libjpeg has been found.

locate libjpeg; ls /usr/lib/libjpeg*; ls /lib/libjpeg* are some other way to find if the lib in installed in the system

There is many other way to check that, if you give us more context (why you need to check if libjpeg is installed) we could give you the best solution for your specific case.

Источник

How to find out the dynamic libraries executables loads when run?

I want to find out the list of dynamic libraries a binary loads when run (With their full paths). I am using CentOS 6.0. How to do this?

8 Answers 8

You can do this with ldd command:

readelf -d $executable | grep ‘NEEDED’

Can be used if you can’t run the executable, e.g. if it was cross compiled, or if you don’t trust it:

In the usual case, ldd invokes the standard dynamic linker (see ld.so(8)) with the LD_TRACE_LOADED_OBJECTS environment variable set to 1, which causes the linker to display the library dependencies. Be aware, however, that in some circumstances, some versions of ldd may attempt to obtain the dependency information by directly executing the program. Thus, you should never employ ldd on an untrusted executable, since this may result in the execution of arbitrary code.

Note that libraries can depend on other libraries, so now you need to find the dependencies.

A naive approach that often works is:

but the more precise method is to understand the ldd search path / cache. I think ldconfig is the way to go.

Choose one, and repeat:

/maps for running processes

Mentioned by Basile, this is useful to find all the libraries currently being used by running executables. E.g.:

shows all currently loaded dynamic dependencies of init (PID 1 ):

This method also shows libraries opened with dlopen , tested with this minimal setup hacked up with a sleep(1000) on Ubuntu 18.04.

Источник

Оцените статью