国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

詳解linux中的strings命令簡介

2019-11-02 16:41:16
字體:
來源:轉載
供稿:網友

在Linux下搞軟件開發的朋友, 幾乎沒有不知道strings命令的。我們先用man strings來看看:

strings - print the strings of printable characters in files. 

 意思是, 打印文件中可打印的字符。  我來補充一下吧, 這個文件可以是文本文件(test.c), 可執行文件(test),  動態鏈接庫(test.o), 靜態鏈接庫(test.a)

脫離代碼地長篇大論而不去實際驗證, 不是我的風格。 還是搞點代碼下菜吧(代碼存在test.c中):

#include <stdio.h>  int add(int x, int y) {     return x + y; }  int main() {     int a = 1;     int b = 2;     int c = add(a, b);     printf("oh, my dear, c is %d/n", c);      return 0; } 

 我們來看看strings test.c的結果:

[taoge@localhost learn_c]$ strings test.c  #include <stdio.h> int add(int x, int y)   return x + y; int main()   int a = 1;   int b = 2;   int c = add(a, b);   printf("oh, my dear, c is %d/n", c);   return 0; [taoge@localhost learn_c]$  

可以看到, 確實打印出了test.c中的很多字符。

下面, 我們對可執行文件用strings試試, 如下:

[taoge@localhost learn_c]$ gcc test.c  [taoge@localhost learn_c]$ strings a.out  /lib/ld-linux.so.2 =$TsU __gmon_start__ libc.so.6 _IO_stdin_used printf __libc_start_main GLIBC_2.0 PTRh  [^_] oh, my dear, c is %d [taoge@localhost learn_c]$  

可以看到, 打印出了a.out中很多字符。

實際上, 如果有目標文件、靜態庫或動態庫, , 也是可以用strings命令進行打印操作的。 我們來看看:

xxx.h文件:

void print(); 

xxx.c文件:

#include <stdio.h> #include "xxx.h"  void print() {   printf("rainy days/n"); } 

然后, 我們來看看怎么制作靜態、動態庫吧(在后續博文中會繼續詳細介紹):

[taoge@localhost learn_strings]$ ls xxx.c xxx.h [taoge@localhost learn_strings]$ gcc -c xxx.c [taoge@localhost learn_strings]$ ar rcs libxxx.a xxx.o [taoge@localhost learn_strings]$ gcc -shared -fPIC -o libxxx.so xxx.o [taoge@localhost learn_strings]$ ls libxxx.a libxxx.so xxx.c xxx.h xxx.o [taoge@localhost learn_strings]$ strings xxx.o rainy days [taoge@localhost learn_strings]$ strings libxxx.a !<arch> /        1437887339 0   0   0    14    ` Rprint xxx.o/     1437887333 501  502  100664 848    ` rainy days GCC: (GNU) 4.4.4 20100726 (Red Hat 4.4.4-13) .symtab .strtab .shstrtab .rel.text .data .bss .rodata .comment .note.GNU-stack xxx.c print puts [taoge@localhost learn_strings]$  [taoge@localhost learn_strings]$  [taoge@localhost learn_strings]$ strings libxxx.so __gmon_start__ _init _fini __cxa_finalize _Jv_RegisterClasses print puts libc.so.6 _edata __bss_start _end GLIBC_2.1.3 GLIBC_2.0 rainy days [taoge@localhost learn_strings]$  

看到了吧。

strings命令很簡單, 看起來好像沒什么, 但實際有很多用途。 下面, 我來舉一個例子。  在大型的軟件開發中, 假設有100個.c/.cpp文件, 這個.cpp文件最終生成10個.so庫, 那么怎樣才能快速知道某個.c/.cpp文件編譯到那個.so庫中去了呢? 當然, 你可能要說, 看makefile不就知道了。 對, 看makefile肯定可以, 但如下方法更好, 直接用命令:

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌恰县| 泰来县| 阿鲁科尔沁旗| 河北区| 清流县| 沾益县| 安溪县| 慈溪市| 武汉市| 炎陵县| 剑阁县| 申扎县| 册亨县| 海阳市| 涟水县| 漳平市| 故城县| 常德市| 泰安市| 冀州市| 若羌县| 微山县| 黄平县| 柞水县| 海丰县| 宿州市| 微山县| 昆山市| 公安县| 广饶县| 牡丹江市| 灵宝市| 吉林省| 哈巴河县| 云林县| 南靖县| 六盘水市| 洮南市| 湄潭县| 桑日县| 宜良县|