linux命令之檢視動態庫符號-nm
阿新 • • 發佈:2018-12-31
在呼叫動態庫的時候,經常出現由於動態庫介面修改或者版本不匹配導致呼叫動態庫找不到函式介面符號的情況。
原因可能有如下幾種:
1.由於c++動態庫編譯沒有加extern c導致函式編譯時加了c++的字首的;
2.系統中有多個庫,程式載入了其他路徑的庫;
3.庫的版本不對,老版本的庫確實沒有新加的介面。
這個時候就可以用nm命令看so中是否有提示找不到的符號。
輸入nm -h檢視nm的選項如下:
用法:nm [選項] [檔案] 列舉 [檔案] 中的符號 (預設為 a.out)。 The options are: -a, --debug-syms Display debugger-only symbols -A, --print-file-name Print name of the input file before every symbol -B Same as --format=bsd -C, --demangle[=STYLE] Decode low-level symbol names into user-level names The STYLE, if specified, can be `auto' (the default), `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java' or `gnat' --no-demangle Do not demangle low-level symbol names -D, --dynamic Display dynamic symbols instead of normal symbols --defined-only Display only defined symbols -e (ignored) -f, --format=FORMAT Use the output format FORMAT. FORMAT can be `bsd', `sysv' or `posix'. The default is `bsd' -g, --extern-only Display only external symbols -l, --line-numbers Use debugging information to find a filename and line number for each symbol -n, --numeric-sort Sort symbols numerically by address -o Same as -A -p, --no-sort Do not sort the symbols -P, --portability Same as --format=posix -r, --reverse-sort Reverse the sense of the sort --plugin NAME Load the specified plugin -S, --print-size Print size of defined symbols -s, --print-armap Include index for symbols from archive members --size-sort Sort symbols by size --special-syms Include special symbols in the output --synthetic Display synthetic symbols as well -t, --radix=RADIX Use RADIX for printing symbol values --target=BFDNAME Specify the target object format as BFDNAME -u, --undefined-only Display only undefined symbols -X 32_64 (ignored) @FILE Read options from FILE -h, --help Display this information -V, --version Display this program's version number nm:支援的目標: elf64-x86-64 elf32-i386 elf32-iamcu elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big pe-x86-64 pe-bigobj-x86-64 pe-i386 plugin srec symbolsrec verilog tekhex binary ihex 將 bug 報告到 <http://www.sourceware.org/bugzilla/>。