using the nm tool to examine dynamic libraries, have discovered significant differences between macOS and Linux:
On Linux:
The -D flag must be specified to obtain the corresponding symbols.
Without -D, no symbols are displayed.
root@be00d9b1c2c9:/lib/aarch64-linux-gnu# nm -gU liblua5.4.so
nm: liblua5.4.so: no symbols
root@be00d9b1c2c9:/lib/aarch64-linux-gnu# nm -gDU liblua5.4.so
0000000000000000 A LUA_5.4
0000000000026a40 T luaL_addgsub@@LUA_5.4
00000000000269a0 T luaL_addlstring@@LUA_5.4
0000000000026a04 T luaL_addstring@@LUA_5.4
On macOS:
There's no -D flag. The nm command displays all symbols (including dynamic ones) by default.
❯ nm -gDU libcjson.dylib
/Library/Developer/CommandLineTools/usr/bin/nm: error: libcjson.dylib: File format has no dynamic symbol table
homebrew/lib on stable via v21.7.2
❯ nm -gU libcjson.dylib
0000000000002ab8 T cJSON_AddArrayToObject
0000000000002720 T cJSON_AddBoolToObject
0000000000002690 T cJSON_AddFalseToObject
0000000000002440 T cJSON_AddItemReferenceToArray
0000000000002520 T cJSON_AddItemReferenceToObject
homebrew/lib on stable via v21.7.2
The reason for this difference is that macOS and Linux use different formats for their executable files and handle symbol tables differently:
On Linux systems, the pkg-config --libs command does not output the -L path for dynamic libraries installed in the system's default search paths
For example:
root@be00d9b1c2c9:/usr/lib/aarch64-linux-gnu# pkg-config --libs lua5.4
-llua5.4
This output only includes the -l flag to specify the library name, but does not include the -L flag to specify the library path. This is because the library is located in the system's default search path.
will search valid path from below conf
/etc/ld.so.conf.d/*.conf/etc/ld.so.conf
nm tool
dynamic symbol
using the
nm
tool to examine dynamic libraries, have discovered significant differences between macOS and Linux: On Linux:The
-D
flag must be specified to obtain the corresponding symbols.Without
-D
, no symbols are displayed.On macOS:
There's no
-D
flag. Thenm
command displays all symbols (including dynamic ones) by default.The reason for this difference is that macOS and Linux use different formats for their executable files and handle symbol tables differently:
Linux uses the ELF format.
macOS uses the Mach-O format.
[x] #829
symbol version
On Linux, symbols may appear with version declarations separated by @@ https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
dynamic lib search
pkg-config
On Linux systems, the pkg-config --libs command does not output the -L path for dynamic libraries installed in the system's default search paths
For example: root@be00d9b1c2c9:/usr/lib/aarch64-linux-gnu# pkg-config --libs lua5.4 -llua5.4
This output only includes the -l flag to specify the library name, but does not include the -L flag to specify the library path. This is because the library is located in the system's default search path.
will search valid path from below conf
/etc/ld.so.conf.d/*.conf
/etc/ld.so.conf
/etc/ld.so.conf.d/*.conf
's fetch , need the os.ReadDirso & dylib
On Linux, dynamic library names end with .so
Related Bugs & Patch