Dynamic libraries:

Dynamic libraries allow you to store compiled code in separate files that are then loaded by your executable at runtime. when you start the executable, it reviews it’s list of dynamic libraries and tries to load them. you can spot the dynamic libraries by their extensions. cmd LC_lOAD_DYLIB

otool -L executable
otool -l executable

-L option prints paths to all dynamic libraries used by an executable.

Command: LC_LOAD_DYLIB indicates that this is a command to load a dynamic library.

otool -l ./luna

Load command 14
          cmd LC_LOAD_DYLIB
      cmdsize 48
         name /usr/lib/libc++.1.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 1500.65.0
compatibility version 1.0.0
Load command 15
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libSystem.B.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 1319.100.3
compatibility version 1.0.0

Here's an overview of how dynamic libraries are handled in various OS environments:

Untitled

The location of dynamic library is actually embedded directly inside the executable. It’s good idea to verify the loader paths before distributing an executable.

Static libraries:

Static libraries are simply a collection of ordinary object files. Conventionally static libraries end with the ".a" suffix. Static libraries are baked into a executable at compile time. The executable is statically linked because a copy of the library is physically part of the executable.

Example

lib_lightgbm.a
libfftw3.a

nm command is used to display the symbol table of object files. If you're dealing with static libraries (.a files) or object files (.o files), nm can be very useful to see the symbols (functions, variables, etc.) defined and referenced in these files. In the output of the nm command, which is used to display the symbol table of object files, each symbol is prefixed with a character that indicates the symbol type. The letters "T" and "U" each signify different types of symbols:

nm ./luna | grep 'LightGBM' | awk 'BEGIN {print "Symbol Type\\tSymbol Name"; print "-----------\\t-----------"} {print $2 "\\t\\t" $3}' | head -n 20
Symbol Type	Symbol Name
-----------	-----------
t		        __ZN8LightGBM10ArrowTableC2ExPK10ArrowArrayPK11ArrowSchema
t		        __ZN8LightGBM10ArrowTableD1Ev
t		        __ZN8LightGBM10ByteBuffer5WriteEPKvm
t		        __ZN8LightGBM10ColSampler11ResetByTreeEv
t		        __ZN8LightGBM10ColSampler15SetTrainingDataEPKNS_7DatasetE
t		        __ZN8LightGBM10ColSampler9GetByNodeEPKNS_4TreeEi
t		        __ZN8LightGBM10ColSamplerC2EPKNS_6ConfigE
t		        __ZN8LightGBM10ColSamplerC2EPKNS_6ConfigE.cold.1
t		        __ZN8LightGBM10ColSamplerD2Ev
T		        __ZN8LightGBM10CreateNoneERKNS_25PredictionEarlyStopConfigE
T		        __ZN8LightGBM10FindGroupsERKNSt3__16vectorINS0_10unique_ptrINS_9BinMapperENS0_14default_deleteIS3_EEEENS0_9allocatorIS6_EEEERKNS1_IiNS7_IiEEEEPPiPKiiiibbPNS1_IaNS7_IaEEEE
t		        __ZN8LightGBM10MAPEMetricD0Ev
t		        __ZN8LightGBM10MAPEMetricD1Ev
t		        __ZN8LightGBM10NDCGMetric4InitERKNS_8MetadataEi
t		        __ZN8LightGBM10NDCGMetricC2ERKNS_6ConfigE
t		        __ZN8LightGBM10NDCGMetricD0Ev
t		        __ZN8LightGBM10NDCGMetricD1Ev
t		        __ZN8LightGBM10NDCGMetricD2Ev

The presence of "T" and "U" symbols helps developers and other tools determine which symbols are provided by an object file and which ones need to be resolved by linking with other files or libraries. This is crucial during the build process to ensure that all references are correctly resolved to create a working executable or library.