How to check linking and dependencies for libraries and applications.
If you are building (cross platform) applications, its good to know how to check linkage/dependencies of applications and libraries. Here are some simple examples for various operating systems.
Linux – ldd
The ldd command prints the shared objects (shared libraries) required by each program or shared object specified on the command line.
[frank@localhost ~]$ ldd /usr/bin/grep linux-vdso.so.1 (0x00007ffc41788000) libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f3148061000) libc.so.6 => /lib64/libc.so.6 (0x00007f3147c9b000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f3147a7d000) /lib64/ld-linux-x86-64.so.2 (0x0000557e7139c000)
Mac – otool
The otool command displays specified parts of object files or libraries.
[frank@mbp ~]$ otool -L /usr/bin/grep /usr/bin/grep: /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5) /usr/lib/liblzma.5.dylib (compatibility version 6.0.0, current version 6.3.0) /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
Windows – dumpbin
The dumpbin command is a COFF/PE Dumper. This can be found in a “Developer Command Prompt for VS2015” terminal, for example.
This is an example involving a simple wxWidgets application.
C:\Users\frank\repos\wxwidgets_ex1\build>dumpbin /dependents main.exe Microsoft (R) COFF/PE Dumper Version 14.00.24215.1 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file main.exe File Type: EXECUTABLE IMAGE Image has the following dependencies: COMCTL32.dll RPCRT4.dll KERNEL32.dll USER32.dll GDI32.dll WINSPOOL.DRV SHELL32.dll ole32.dll OLEAUT32.dll COMDLG32.dll ADVAPI32.dll MSVCP140D.dll SHLWAPI.dll MSIMG32.dll VERSION.dll VCRUNTIME140D.dll ucrtbased.dll Summary 1000 .00cfg 47000 .data 1000 .gfids 7000 .idata 150000 .rdata 43000 .reloc 1000 .rsrc 414000 .text 1000 .tls