本页面记录本人在Linux下进行C++开发时使用的常用命令,注意这里不包括比如ls,mv等linux命令,这里会持续更新。
首先假设你只有一个源程序文件,叫vec.cpp,编译后的可执行程序叫vec(本文最后附有该程序Demo)。
本人是在Centos6.4 64bit系统上进行测试的,GCC版本是4.4.7。
1. strings命令:查看系统glibc支持的版本
[root@lzv6 c++]# strings /usr/lib64/libstdc++.so.6 | grep GLIBC
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBC_2.2.5
GLIBC_2.3
GLIBC_2.4
GLIBC_2.3.2
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH
[root@lzv6 c++]# strings /lib64/libc.so.6 | grep GLIBC_
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_PRIVATE
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命令:显示目标文件的依赖库
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
4. objdump命令:查看目标文件的动态引用符号表
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
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. c++filt命令:显示未重整(unmangled)的原函数声明
1 [root@lzv6 c++]# nm vec | grep 'print' 2 00000000004009e0 t _GLOBAL__I__Z9print_vecRKSt6vectorIiSaIiEE 3 0000000000400b00 T _Z9print_inti 4 0000000000400a90 T _Z9print_strPc 5 0000000000400a10 T _Z9print_vecRKSt6vectorIiSaIiEE 6 [root@lzv6 c++]# c++filt _Z9print_inti 7 print_int(int) 8 [root@lzv6 c++]# nm vec | grep print | c++filt 9 00000000004009e0 t global constructors keyed to _Z9print_vecRKSt6vectorIiSaIiEE 10 0000000000400b00 T print_int(int) 11 0000000000400a90 T print_str(char*) 12 0000000000400a10 T print_vec(std::vector<int, std::allocator<int> > const&)
8. nm命令:显示目标文件的所有符号清单
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
9. strace命令:显示在预处理的时候读取的所有头文件
1 [root@lzv6 c++]# strace -f -e open cpp vec.cpp -o /dev/null 2>&1 | grep -v ENOENT | awk '{print $3}' 2 = 3 = 4 = 5 = 6 = 7 = 8 attached 9 open("/etc/ld.so.cache", 10 open("/usr/lib64/libmpfr.so.1", 11 open("/usr/lib64/libgmp.so.3", 12 open("/lib64/libdl.so.2", 13 open("/lib64/libc.so.6", 14 open("/usr/lib/locale/locale-archive", 15 open("/usr/share/locale/locale.alias", 16 open("/usr/share/locale/zh_CN/LC_MESSAGES/gcc.mo", 17 open("/usr/lib64/gconv/gconv-modules.cache", 18 open("/proc/meminfo", 19 open("/proc/meminfo", 20 open("/proc/meminfo", 21 open("/dev/null", 22 open("vec.cpp", 23 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iostream", 24 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux/bits/c++config.h", 25 open("/usr/include/bits/wordsize.h", 26 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux/bits/os_defines.h", 27 open("/usr/include/features.h", 28 open("/usr/include/sys/cdefs.h", 29 open("/usr/include/bits/wordsize.h", 30 open("/usr/include/gnu/stubs.h", 31 open("/usr/include/bits/wordsize.h", 32 open("/usr/include/gnu/stubs-64.h", 33 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux/bits/cpu_defines.h", 34 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream", 35 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ios", 36 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iosfwd", 37 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stringfwd.h", 38 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/postypes.h", 39 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwchar", 40 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cstddef", 41 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h", 42 open("/usr/include/wchar.h", 43 open("/usr/include/stdio.h", 44 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stdarg.h", 45 open("/usr/include/bits/wchar.h", 46 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h", 47 open("/usr/include/xlocale.h", 48 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/exception", 49 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/char_traits.h", 50 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algobase.h", 51 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cstddef", 52 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h", 53 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/functexcept.h", 54 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/exception_defines.h", 55 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/cpp_type_traits.h", 56 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ext/type_traits.h", 57 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ext/numeric_traits.h", 58 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h", 59 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/move.h", 60 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cstddef", 61 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h", 62 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/concept_check.h", 63 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_iterator_base_types.h", 64 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cstddef", 65 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h", 66 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_iterator_base_funcs.h", 67 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_iterator.h", 68 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/debug/debug.h", 69 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwchar", 70 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cstddef", 71 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h", 72 open("/usr/include/wchar.h", 73 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/localefwd.h", 74 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux/bits/c++locale.h", 75 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/clocale", 76 open("/usr/include/locale.h", 77 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h", 78 open("/usr/include/bits/locale.h", 79 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cstddef", 80 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h", 81 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cctype", 82 open("/usr/include/ctype.h", 83 open("/usr/include/bits/types.h", 84 open("/usr/include/bits/wordsize.h", 85 open("/usr/include/bits/typesizes.h", 86 open("/usr/include/endian.h", 87 open("/usr/include/bits/endian.h", 88 open("/usr/include/bits/byteswap.h", 89 open("/usr/include/bits/wordsize.h", 90 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/ios_base.h", 91 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ext/atomicity.h", 92 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux/bits/gthr.h", 93 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux/bits/gthr-default.h", 94 open("/usr/include/pthread.h", 95 open("/usr/include/sched.h", 96 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h", 97 open("/usr/include/time.h", 98 open("/usr/include/bits/sched.h", 99 open("/usr/include/time.h", 100 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h", 101 open("/usr/include/bits/time.h", 102 open("/usr/include/bits/pthreadtypes.h", 103 open("/usr/include/bits/wordsize.h", 104 open("/usr/include/bits/setjmp.h", 105 open("/usr/include/bits/wordsize.h", 106 open("/usr/include/bits/wordsize.h", 107 open("/usr/include/unistd.h", 108 open("/usr/include/bits/posix_opt.h", 109 open("/usr/include/bits/environments.h", 110 open("/usr/include/bits/wordsize.h", 111 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h", 112 open("/usr/include/bits/confname.h", 113 open("/usr/include/getopt.h", 114 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux/bits/atomic_word.h", 115 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/locale_classes.h", 116 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/string", 117 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/allocator.h", 118 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux/bits/c++allocator.h", 119 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ext/new_allocator.h", 120 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/new", 121 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cstddef", 122 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h", 123 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/ostream_insert.h", 124 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cxxabi-forced.h", 125 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_function.h", 126 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/backward/binders.h", 127 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_string.h", 128 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/initializer_list", 129 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_string.tcc", 130 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/locale_classes.tcc", 131 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/streambuf", 132 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/streambuf.tcc", 133 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_ios.h", 134 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/locale_facets.h", 135 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwctype", 136 open("/usr/include/wctype.h", 137 open("/usr/include/wchar.h", 138 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cctype", 139 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux/bits/ctype_base.h", 140 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/streambuf_iterator.h", 141 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux/bits/ctype_inline.h", 142 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/locale_facets.tcc", 143 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_ios.tcc", 144 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/ostream.tcc", 145 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/istream", 146 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/istream.tcc", 147 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/vector", 148 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_construct.h", 149 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_uninitialized.h", 150 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_vector.h", 151 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_bvector.h", 152 open("/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/vector.tcc", 153 detached 154 (Child
我的测试代码:
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