Linux下C++开发常用命令

      本页面记录本人在Linux下进行C++开发时使用的常用命令,注意这里不包括比如ls,mv等linux命令,这里会持续更新。
首先假设你只有一个源程序文件,叫vec.cpp,编译后的可执行程序叫vec(本文最后附有该程序Demo)。

本人是在Centos6.4 64bit系统上进行测试的,GCC版本是4.4.7。

1. strings命令:查看系统glibc支持的版本

Linux下C++开发常用命令
 1 [root@lzv6 c++]# strings /lib64/libc.so.6 | grep GLIBC_
 2 GLIBC_2.2.5
 3 GLIBC_2.2.6
 4 GLIBC_2.3
 5 GLIBC_2.3.2
 6 GLIBC_2.3.3
 7 GLIBC_2.3.4
 8 GLIBC_2.4
 9 GLIBC_2.5
10 GLIBC_2.6
11 GLIBC_2.7
12 GLIBC_2.8
13 GLIBC_2.9
14 GLIBC_2.10
15 GLIBC_2.11
16 GLIBC_2.12
17 GLIBC_PRIVATE
Linux下C++开发常用命令

2. g++ -E选项:预处理源文件

1 [root@lzv6 c++]# g++ -E -o vec2.cpp vec.cpp 
2 [root@lzv6 c++]# wc vec.cpp vec2.cpp 
3     33     71    557 vec.cpp
4  20958  45683 534803 vec2.cpp
5  20991  45754 535360 总用量

 上面每行分别代表行数、单次数、字节数。
 从这里也可以看出引入多余头文件是件多么可怕的事情,多引入一个头文件,就要预处理N行。你可以试着#include <stdio.h>,然后再看看增加了多少行。

3. ldd命令:显示目标文件的依赖库

Linux下C++开发常用命令
 1     [root@lzv6 c++]# ldd vec
 2     linux-vdso.so.1 =>  (0x00007fff8fbff000)
 3     libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003317800000)
 4     libm.so.6 => /lib64/libm.so.6 (0x000000309ca00000)
 5     libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003317400000)
 6     libc.so.6 => /lib64/libc.so.6 (0x000000309ce00000)
 7     /lib64/ld-linux-x86-64.so.2 (0x000000309c600000)
 8     
 9     [root@lzv6 c++]# ldd -v vec  // -v 表示 打印所有信息,例如包括符号的版本信息
10     linux-vdso.so.1 =>  (0x00007fff585ff000)
11     libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003317800000)
12     libm.so.6 => /lib64/libm.so.6 (0x000000309ca00000)
13     libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003317400000)
14     libc.so.6 => /lib64/libc.so.6 (0x000000309ce00000)
15     /lib64/ld-linux-x86-64.so.2 (0x000000309c600000)
16 
17     Version information:
18     ./vec:
19         libgcc_s.so.1 (GCC_3.0) => /lib64/libgcc_s.so.1
20         libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
21         libstdc++.so.6 (CXXABI_1.3) => /usr/lib64/libstdc++.so.6
22         libstdc++.so.6 (GLIBCXX_3.4) => /usr/lib64/libstdc++.so.6
23     /usr/lib64/libstdc++.so.6:
24         libm.so.6 (GLIBC_2.2.5) => /lib64/libm.so.6
25         ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
26         libgcc_s.so.1 (GCC_4.2.0) => /lib64/libgcc_s.so.1
27         libgcc_s.so.1 (GCC_3.3) => /lib64/libgcc_s.so.1
28         libgcc_s.so.1 (GCC_3.0) => /lib64/libgcc_s.so.1
29         libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
30         libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
31         libc.so.6 (GLIBC_2.3.2) => /lib64/libc.so.6
32         libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
33     /lib64/libm.so.6:
34         libc.so.6 (GLIBC_PRIVATE) => /lib64/libc.so.6
35         libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
36     /lib64/libgcc_s.so.1:
37         libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
38         libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
39     /lib64/libc.so.6:
40         ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
41         ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
Linux下C++开发常用命令

4. objdump命令:查看目标文件的动态引用符号表

Linux下C++开发常用命令
 1 [root@lzv6 c++]# objdump -T vec
 2 
 3 vec:     file format elf64-x86-64
 4 
 5 DYNAMIC SYMBOL TABLE:
 6 0000000000000000      DF *UND*    0000000000000000  GLIBCXX_3.4 _ZSt20__throw_length_errorPKc
 7 0000000000000000      DF *UND*    0000000000000000  GLIBCXX_3.4 _ZNSolsEi
 8 0000000000000000  w   D  *UND*    0000000000000000              __gmon_start__
 9 0000000000000000  w   D  *UND*    0000000000000000              _Jv_RegisterClasses
10 0000000000000000      DF *UND*    0000000000000000  GLIBCXX_3.4 _ZdlPv
11 0000000000000000      DF *UND*    0000000000000000  CXXABI_1.3  __cxa_rethrow
12 0000000000000000      DF *UND*    0000000000000000  GLIBCXX_3.4 _ZNSt8ios_base4InitC1Ev
13 0000000000000000      DF *UND*    0000000000000000  GLIBC_2.2.5 __libc_start_main
14 0000000000000000      DF *UND*    0000000000000000  GLIBC_2.2.5 __cxa_atexit
15 0000000000000000      DF *UND*    0000000000000000  GLIBCXX_3.4 _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
16 0000000000000000      DF *UND*    0000000000000000  GLIBC_2.2.5 memmove
17 0000000000000000      DF *UND*    0000000000000000  CXXABI_1.3  __cxa_end_catch
18 0000000000000000      DF *UND*    0000000000000000  GLIBCXX_3.4 _ZSt17__throw_bad_allocv
19 0000000000000000      DF *UND*    0000000000000000  CXXABI_1.3  __cxa_begin_catch
20 0000000000000000      DF *UND*    0000000000000000  GLIBCXX_3.4 _Znwm
21 0000000000000000      DF *UND*    0000000000000000  GCC_3.0     _Unwind_Resume
22 0000000000400910      DF *UND*    0000000000000000  GLIBCXX_3.4 _ZNSt8ios_base4InitD1Ev
23 00000000006026e0 g    DO .bss    0000000000000110  GLIBCXX_3.4 _ZSt4cout
24 0000000000400970      DF *UND*    0000000000000000  CXXABI_1.3  __gxx_personality_v0    
Linux下C++开发常用命令

5. objdump命令:查看目标文件引用了GLIBC的哪些版本中的哪些函数

1 [root@lzv6 c++]# objdump -T vec | grep GLIBC_
2 0000000000000000      DF *UND*    0000000000000000  GLIBC_2.2.5 __libc_start_main
3 0000000000000000      DF *UND*    0000000000000000  GLIBC_2.2.5 __cxa_atexit
4 0000000000000000      DF *UND*    0000000000000000  GLIBC_2.2.5 memmove    

6. nm命令:显示vec程序中使用的函数

1 [root@lzv6 c++]# nm -o vec | grep print
2 vec:0000000000400c50 t _GLOBAL__I__Z9print_vecRKSt6vectorIiSaIiEE
3 vec:0000000000400b0c T _Z9print_inti
4 vec:0000000000400b42 T _Z9print_strPc
5 vec:0000000000400a84 T _Z9print_vecRKSt6vectorIiSaIiEE

7. nm命令:显示目标文件的所有符号清单 

Linux下C++开发常用命令
  1 [root@lzv6 c++]# nm -o vec
  2 vec:0000000000602460 d _DYNAMIC
  3 vec:0000000000602628 d _GLOBAL_OFFSET_TABLE_
  4 vec:0000000000400c50 t _GLOBAL__I__Z9print_vecRKSt6vectorIiSaIiEE
  5 vec:00000000004019b8 R _IO_stdin_used
  6 vec:                 w _Jv_RegisterClasses
  7 vec:                 U _Unwind_Resume@@GCC_3.0
  8 vec:0000000000400c10 t _Z41__static_initialization_and_destruction_0ii
  9 vec:0000000000400b0c T _Z9print_inti
 10 vec:0000000000400b42 T _Z9print_strPc
 11 vec:0000000000400a84 T _Z9print_vecRKSt6vectorIiSaIiEE
 12 vec:0000000000401504 W _ZN9__gnu_cxx13new_allocatorIiE10deallocateEPim
 13 vec:00000000004014b6 W _ZN9__gnu_cxx13new_allocatorIiE7destroyEPi
 14 vec:00000000004015e8 W _ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv
 15 vec:0000000000400eae W _ZN9__gnu_cxx13new_allocatorIiE9constructEPiRKi
 16 vec:0000000000401664 W _ZN9__gnu_cxx13new_allocatorIiEC1Ev
 17 vec:0000000000401664 W _ZN9__gnu_cxx13new_allocatorIiEC2Ev
 18 vec:00000000004014fa W _ZN9__gnu_cxx13new_allocatorIiED1Ev
 19 vec:00000000004014fa W _ZN9__gnu_cxx13new_allocatorIiED2Ev
 20 vec:00000000004014c4 W _ZN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEC1ERKS1_
 21 vec:00000000004014c4 W _ZN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEC2ERKS1_
 22 vec:00000000004013fb W _ZN9__gnu_cxxmiIPiSt6vectorIiSaIiEEEENS_17__normal_iteratorIT_T0_E15difference_typeERKS8_SB_
 23 vec:00000000004016bc W _ZNK9__gnu_cxx13new_allocatorIiE8max_sizeEv
 24 vec:00000000004012a6 W _ZNK9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEE4baseEv
 25 vec:00000000004012fa W _ZNK9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEdeEv
 26 vec:00000000004016ae W _ZNKSt12_Vector_baseIiSaIiEE19_M_get_Tp_allocatorEv
 27 vec:000000000040130c W _ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc
 28 vec:0000000000400c78 W _ZNKSt6vectorIiSaIiEE4sizeEv
 29 vec:000000000040159a W _ZNKSt6vectorIiSaIiEE8max_sizeEv
 30 vec:0000000000400ca2 W _ZNKSt6vectorIiSaIiEEixEm
 31 vec:00000000004014e0 W _ZNSaIiEC1Ev
 32 vec:00000000004014e0 W _ZNSaIiEC2Ev
 33 vec:0000000000401232 W _ZNSaIiED1Ev
 34 vec:0000000000401232 W _ZNSaIiED2Ev
 35 vec:                 U _ZNSolsEi@@GLIBCXX_3.4
 36 vec:0000000000401861 W _ZNSt11__copy_moveILb0ELb1ESt26random_access_iterator_tagE8__copy_mIiEEPT_PKS3_S6_S4_
 37 vec:0000000000401526 W _ZNSt12_Destroy_auxILb1EE9__destroyIPiEEvT_S3_
 38 vec:0000000000401442 W _ZNSt12_Vector_baseIiSaIiEE11_M_allocateEm
 39 vec:00000000004011f4 W _ZNSt12_Vector_baseIiSaIiEE12_Vector_implC1Ev
 40 vec:00000000004011f4 W _ZNSt12_Vector_baseIiSaIiEE12_Vector_implC2Ev
 41 vec:0000000000400dc4 W _ZNSt12_Vector_baseIiSaIiEE12_Vector_implD1Ev
 42 vec:0000000000400dc4 W _ZNSt12_Vector_baseIiSaIiEE12_Vector_implD2Ev
 43 vec:000000000040124c W _ZNSt12_Vector_baseIiSaIiEE13_M_deallocateEPim
 44 vec:0000000000400e76 W _ZNSt12_Vector_baseIiSaIiEE19_M_get_Tp_allocatorEv
 45 vec:0000000000400dde W _ZNSt12_Vector_baseIiSaIiEEC1Ev
 46 vec:0000000000400dde W _ZNSt12_Vector_baseIiSaIiEEC2Ev
 47 vec:0000000000400df8 W _ZNSt12_Vector_baseIiSaIiEED1Ev
 48 vec:0000000000400df8 W _ZNSt12_Vector_baseIiSaIiEED2Ev
 49 vec:0000000000401534 W _ZNSt12__miter_baseIPiLb0EE3__bES0_
 50 vec:000000000040166e W _ZNSt12__niter_baseIPiLb0EE3__bES0_
 51 vec:00000000004016fd W _ZNSt20__copy_move_backwardILb0ELb1ESt26random_access_iterator_tagE13__copy_move_bIiEEPT_PKS3_S6_S4_
 52 vec:0000000000401765 W _ZNSt20__uninitialized_copyILb1EE18uninitialized_copyIPiS2_EET0_T_S4_S3_
 53 vec:0000000000400ee6 W _ZNSt6vectorIiSaIiEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPiS1_EERKi
 54 vec:00000000004011ca W _ZNSt6vectorIiSaIiEE3endEv
 55 vec:00000000004013d6 W _ZNSt6vectorIiSaIiEE5beginEv
 56 vec:0000000000400d4a W _ZNSt6vectorIiSaIiEE9push_backERKi
 57 vec:0000000000400cc2 W _ZNSt6vectorIiSaIiEEC1Ev
 58 vec:0000000000400cc2 W _ZNSt6vectorIiSaIiEEC2Ev
 59 vec:0000000000400cdc W _ZNSt6vectorIiSaIiEED1Ev
 60 vec:0000000000400cdc W _ZNSt6vectorIiSaIiEED2Ev
 61 vec:                 U _ZNSt8ios_base4InitC1Ev@@GLIBCXX_3.4
 62 vec:                 U _ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4
 63 vec:0000000000401830 W _ZSt13__copy_move_aILb0EPiS0_ET1_T0_S2_S1_
 64 vec:00000000004012b4 W _ZSt13copy_backwardIPiS0_ET0_T_S2_S1_
 65 vec:00000000004017d8 W _ZSt14__copy_move_a2ILb0EPiS0_ET1_T0_S2_S1_
 66 vec:                 U _ZSt17__throw_bad_allocv@@GLIBCXX_3.4
 67 vec:00000000004016d0 W _ZSt18uninitialized_copyIPiS0_ET0_T_S2_S1_
 68 vec:                 U _ZSt20__throw_length_errorPKc@@GLIBCXX_3.4
 69 vec:000000000040167c W _ZSt22__copy_move_backward_aILb0EPiS0_ET1_T0_S2_S1_
 70 vec:0000000000401633 W _ZSt22__uninitialized_copy_aIPiS0_iET0_T_S2_S1_RSaIT1_E
 71 vec:000000000040147a W _ZSt22__uninitialized_move_aIPiS0_SaIiEET0_T_S3_S2_RT1_
 72 vec:0000000000401542 W _ZSt23__copy_move_backward_a2ILb0EPiS0_ET1_T0_S2_S1_
 73 vec:00000000004015bc W _ZSt3maxImERKT_S2_S2_
 74 vec:0000000000401792 W _ZSt4copyIPiS0_ET0_T_S2_S1_
 75 vec:00000000006026e0 B _ZSt4cout@@GLIBCXX_3.4
 76 vec:0000000000401280 W _ZSt8_DestroyIPiEvT_S1_
 77 vec:0000000000400e84 W _ZSt8_DestroyIPiiEvT_S1_RSaIT0_E
 78 vec:0000000000602800 b _ZStL8__ioinit
 79 vec:                 U _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@@GLIBCXX_3.4
 80 vec:                 U _ZdlPv@@GLIBCXX_3.4
 81 vec:                 U _Znwm@@GLIBCXX_3.4
 82 vec:0000000000400c65 W _ZnwmPv
 83 vec:0000000000602440 d __CTOR_END__
 84 vec:0000000000602430 d __CTOR_LIST__
 85 vec:0000000000602450 D __DTOR_END__
 86 vec:0000000000602448 d __DTOR_LIST__
 87 vec:00000000004023d0 r __FRAME_END__
 88 vec:0000000000602458 d __JCR_END__
 89 vec:0000000000602458 d __JCR_LIST__
 90 vec:00000000006026c4 A __bss_start
 91 vec:                 U __cxa_atexit@@GLIBC_2.2.5
 92 vec:                 U __cxa_begin_catch@@CXXABI_1.3
 93 vec:                 U __cxa_end_catch@@CXXABI_1.3
 94 vec:                 U __cxa_rethrow@@CXXABI_1.3
 95 vec:00000000006026c0 D __data_start
 96 vec:0000000000401970 t __do_global_ctors_aux
 97 vec:00000000004009f0 t __do_global_dtors_aux
 98 vec:00000000004019c0 R __dso_handle
 99 vec:                 w __gmon_start__
100 vec:                 U __gxx_personality_v0@@CXXABI_1.3
101 vec:000000000060242c d __init_array_end
102 vec:000000000060242c d __init_array_start
103 vec:00000000004018d0 T __libc_csu_fini
104 vec:00000000004018e0 T __libc_csu_init
105 vec:                 U __libc_start_main@@GLIBC_2.2.5
106 vec:00000000006026c4 A _edata
107 vec:0000000000602808 A _end
108 vec:00000000004019a8 T _fini
109 vec:0000000000400878 T _init
110 vec:00000000004009a0 T _start
111 vec:00000000004009cc t call_gmon_start
112 vec:00000000006027f0 b completed.6349
113 vec:00000000006026c0 W data_start
114 vec:00000000006027f8 b dtor_idx.6351
115 vec:0000000000400a60 t frame_dummy
116 vec:0000000000400b7b T main
117 vec:                 U memmove@@GLIBC_2.2.5
Linux下C++开发常用命令

 

我的测试代码: 

Linux下C++开发常用命令
 1 #include <iostream>
 2 #include <vector>
 3 
 4 void print_vec(const std::vector<int>& vec)
 5 {
 6     std::cout << "print vec : ";
 7     size_t size = vec.size();
 8     for(size_t i = 0; i<size; i++)
 9         std::cout << vec[i] << "\t";
10     std::cout << "\n";
11 }
12 
13 void print_int(int i)
14 {
15     std::cout<<"print_int : " << i << "\n"; 
16 }
17 
18 void print_str(char* str)
19 {
20     std::cout<<"print_str : " << str << "\n"; 
21 }
22 
23 int main()
24 {
25     std::vector<int> vec;
26     vec.push_back(1);
27     
28     print_vec(vec);
29     print_int(vec.size());
30     print_str("hello world!");
31 
32     return 0;
33 }
34 
35 //编译:
36 //g++ -o vec vec.cpp
Linux下C++开发常用命令

 

 

 

Linux下C++开发常用命令,布布扣,bubuko.com

Linux下C++开发常用命令

上一篇:JavaScript性能优化大家多多评论谢谢


下一篇:JS监听H5返回