• UUID生成库libuuid和crossguid


    libuuid是一个开源的用于生成UUID(Universally Unique Identifier,通用唯一标识符)的库。

    可从https://sourceforge.net/projects/libuuid/ 下载,最新版本为1.0.3,更新于2013年4月27日,此库仅支持在类Linux下编译使用。

    之前在Windows上,我们产生guid(uuid在Windows上的叫法,是一个东西)可以使用API函数CoCreateGuid。

    CrossGuid是一个最小的跨平台C ++ GUID库。它在给定平台上使用最好的本机GUID / UUID生成器,并具有用于解析,字符串化和比较ID的通用类。

    可从https://github.com/graeme-hill/crossguid下载使用

    接下来,我们在linux ubuntu上编译学习以下这两个库:

    • libuuid

      

       libuuid已经为我们提供了configure,直接./configure & make & make install三部曲即可,最终编译生成libuuid.a供程序链接使用,自带的一个C测试例子test_uuid.c,全部的终端执行如下:

    Shell code 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
     
    michael@ubuntu:~/git$ cd ./libuuid-1.0.3/
    michael@ubuntu:~/git/libuuid-
    1.0.3$ ls
    aclocal.m4    config.h.in   depcomp      Makefile.in  test_uuid.c  uuidP.h
    all-io.h      config.
    sub    gen_uuid.c   missing      unpack.c     uuid_time.c
    c.h           configure     install-sh   
    pack.c       unparse.c
    clear.c       configure.ac  isnull.c     parse.c      uuidd.h
    compare.c     copy.c        ltmain.sh    randutils.c  uuid.h
    config.guess  COPYING       Makefile.am  randutils.h  uuid.pc.in
    michael@ubuntu:~/git/libuuid-
    1.0.3$ ./configure 
    checking 
    for a BSD-compatible install... /usr/bin/install -c
    checking whether build environment is sane... yes
    checking 
    for a thread-safe mkdir -p... /bin/mkdir -p
    checking 
    for gawk... no
    checking 
    for mawk... mawk
    checking whether make sets $(MAKE)... yes
    checking whether make supports nested variables... yes
    checking build 
    system type... x86_64-unknown-linux-gnu
    checking host 
    system type... x86_64-unknown-linux-gnu
    checking how to 
    print strings... printf
    checking 
    for style of include used by make... GNU
    checking 
    for gcc... gcc
    checking whether the C compiler works... yes
    checking 
    for C compiler default output file name... a.out
    checking 
    for suffix of executables... 
    checking whether we are cross compiling... 
    no
    checking 
    for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether gcc accepts -g... yes
    checking 
    for gcc option to accept ISO C89... none needed
    checking dependency style of gcc... gcc3
    checking 
    for a sed that does not truncate output... /bin/sed
    checking 
    for grep that handles long lines and -e... /bin/grep
    checking 
    for egrep... /bin/grep -E
    checking 
    for fgrep... /bin/grep -F
    checking 
    for ld used by gcc... /usr/bin/ld
    checking 
    if the linker (/usr/bin/ld) is GNU ld... yes
    checking 
    for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
    checking the name lister (/usr/bin/nm -B) interface... BSD nm
    checking whether ln -
    s works... yes
    checking the maximum 
    length of command line arguments... 1572864
    checking whether the shell understands some XSI constructs... yes
    checking whether the shell understands 
    "+="... yes
    checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu 
    format... func_convert_file_noop
    checking how to convert x86_64-unknown-linux-gnu file names to toolchain 
    format... func_convert_file_noop
    checking 
    for /usr/bin/ld option to reload object files... -r
    checking 
    for objdump... objdump
    checking how to recognize dependent libraries... pass_all
    checking 
    for dlltool... no
    checking how to associate runtime 
    and link libraries... printf %s
    checking 
    for ar... ar
    checking 
    for archiver @FILE support... @
    checking 
    for strip... strip
    checking 
    for ranlib... ranlib
    checking command to parse /usr/bin/nm -B output from gcc object... ok
    checking 
    for sysroot... no
    checking 
    for mt... mt
    checking 
    if mt is a manifest tool... no
    checking how to run the C preprocessor... gcc -E
    checking 
    for ANSI C header files... yes
    checking 
    for sys/types.h... yes
    checking 
    for sys/stat.h... yes
    checking 
    for stdlib.h... yes
    checking 
    for string.h... yes
    checking 
    for memory.h... yes
    checking 
    for strings.h... yes
    checking 
    for inttypes.h... yes
    checking 
    for stdint.h... yes
    checking 
    for unistd.h... yes
    checking 
    for dlfcn.h... yes
    checking 
    for objdir... .libs
    checking 
    if gcc supports -fno-rtti -fno-exceptions... no
    checking 
    for gcc option to produce PIC... -fPIC -DPIC
    checking 
    if gcc PIC flag -fPIC -DPIC works... yes
    checking 
    if gcc static flag -static works... yes
    checking 
    if gcc supports -c -o file.o... yes
    checking 
    if gcc supports -c -o file.o... (cached) yes
    checking whether the gcc linker (/usr/bin/ld -
    m elf_x86_64) supports shared libraries... yes
    checking whether -
    lc should be explicitly linked in... no
    checking dynamic linker characteristics... GNU/Linux ld.so
    checking how to hardcode library paths into programs... immediate
    checking whether stripping libraries is possible... yes
    checking 
    if libtool supports shared libraries... yes
    checking whether to build shared libraries... yes
    checking whether to build static libraries... yes
    checking 
    for gcc... (cached) gcc
    checking whether we are using the GNU C compiler... (cached) yes
    checking whether gcc accepts -g... (cached) yes
    checking 
    for gcc option to accept ISO C89... (cached) none needed
    checking dependency style of gcc... (cached) gcc3
    checking 
    for library containing socket... none required
    checking 
    fcntl.h usability... yes
    checking 
    fcntl.h presence... yes
    checking 
    for fcntl.h... yes
    checking 
    for inttypes.h... (cached) yes
    checking limits.h usability... yes
    checking limits.h presence... yes
    checking 
    for limits.h... yes
    checking netinet/in.h usability... yes
    checking netinet/in.h presence... yes
    checking 
    for netinet/in.h... yes
    checking 
    for stdlib.h... (cached) yes
    checking 
    for string.h... (cached) yes
    checking sys/file.h usability... yes
    checking sys/file.h presence... yes
    checking 
    for sys/file.h... yes
    checking sys/
    ioctl.h usability... yes
    checking sys/
    ioctl.h presence... yes
    checking 
    for sys/ioctl.h... yes
    checking sys/
    socket.h usability... yes
    checking sys/
    socket.h presence... yes
    checking 
    for sys/socket.h... yes
    checking sys/
    time.h usability... yes
    checking sys/
    time.h presence... yes
    checking 
    for sys/time.h... yes
    checking 
    for unistd.h... (cached) yes
    checking whether _SC_HOST_NAME_MAX is declared... yes
    checking 
    for int32_t... yes
    checking 
    for mode_t... yes
    checking 
    for size_t... yes
    checking 
    for ssize_t... yes
    checking 
    for uint16_t... yes
    checking 
    for uint32_t... yes
    checking 
    for uint64_t... yes
    checking 
    for uint8_t... yes
    checking 
    for ftruncate... yes
    checking 
    for gettimeofday... yes
    checking 
    for memset... yes
    checking 
    for socket... yes
    checking 
    for strtoul... yes
    checking 
    for usleep... yes
    checking 
    for srandom... yes
    checking that generated files are newer than configure... done
    configure: creating ./config.status
    config.status: creating Makefile
    config.status: creating uuid.pc
    config.status: creating config.h
    config.status: executing depfiles commands
    config.status: executing libtool commands
    michael@ubuntu:~/git/libuuid-
    1.0.3$ make
    make  all-am
    make[
    1]: Entering directory '/home/michael/git/libuuid-1.0.3'
    /bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.    -I. -g -O2 -MT libuuid_la-clear.lo -MD -MP -MF .deps/libuuid_la-clear.Tpo -c -o libuuid_la-clear.lo `test -f 
    'clear.c' || echo './'`clear.c
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-clear.lo -MD -MP -MF .deps/libuuid_la-clear.Tpo -c clear.c  -fPIC -DPIC -o .libs/libuuid_la-clear.o
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-clear.lo -MD -MP -MF .deps/libuuid_la-clear.Tpo -c clear.c -o libuuid_la-clear.o >/dev/null 
    2>&1
    mv -f .deps/libuuid_la-clear.Tpo .deps/libuuid_la-clear.Plo
    /bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.    -I. -g -O2 -MT libuuid_la-compare.lo -MD -MP -MF .deps/libuuid_la-compare.Tpo -c -o libuuid_la-compare.lo `test -f 
    'compare.c' || echo './'`compare.c
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-compare.lo -MD -MP -MF .deps/libuuid_la-compare.Tpo -c compare.c  -fPIC -DPIC -o .libs/libuuid_la-compare.o
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-compare.lo -MD -MP -MF .deps/libuuid_la-compare.Tpo -c compare.c -o libuuid_la-compare.o >/dev/null 
    2>&1
    mv -f .deps/libuuid_la-compare.Tpo .deps/libuuid_la-compare.Plo
    /bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.    -I. -g -O2 -MT libuuid_la-copy.lo -MD -MP -MF .deps/libuuid_la-copy.Tpo -c -o libuuid_la-copy.lo `test -f 
    'copy.c' || echo './'`copy.c
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-copy.lo -MD -MP -MF .deps/libuuid_la-copy.Tpo -c copy.c  -fPIC -DPIC -o .libs/libuuid_la-copy.o
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-copy.lo -MD -MP -MF .deps/libuuid_la-copy.Tpo -c copy.c -o libuuid_la-copy.o >/dev/null 
    2>&1
    mv -f .deps/libuuid_la-copy.Tpo .deps/libuuid_la-copy.Plo
    /bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.    -I. -g -O2 -MT libuuid_la-gen_uuid.lo -MD -MP -MF .deps/libuuid_la-gen_uuid.Tpo -c -o libuuid_la-gen_uuid.lo `test -f 
    'gen_uuid.c' || echo './'`gen_uuid.c
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-gen_uuid.lo -MD -MP -MF .deps/libuuid_la-gen_uuid.Tpo -c gen_uuid.c  -fPIC -DPIC -o .libs/libuuid_la-gen_uuid.o
    In file included from /usr/include/x86_64-linux-gnu/bits/libc-header-start.h:
    33,
                     from /usr/include/stdio.h:
    27,
                     from gen_uuid.c:
    46:
    /usr/include/features.h:
    184:3: warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp]
     # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
       ^~~~~~~
    gen_uuid.c: In function 
    'get_clock':
    gen_uuid.c:
    297:10: warning: implicit declaration of function 'flock'; did you mean 'clock'? [-Wimplicit-function-declaration]
       
    while (flock(state_fd, LOCK_EX) < 0) {
              ^~~~~
              clock
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-gen_uuid.lo -MD -MP -MF .deps/libuuid_la-gen_uuid.Tpo -c gen_uuid.c -o libuuid_la-gen_uuid.o >/dev/null 
    2>&1
    mv -f .deps/libuuid_la-gen_uuid.Tpo .deps/libuuid_la-gen_uuid.Plo
    /bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.    -I. -g -O2 -MT libuuid_la-isnull.lo -MD -MP -MF .deps/libuuid_la-isnull.Tpo -c -o libuuid_la-isnull.lo `test -f 
    'isnull.c' || echo './'`isnull.c
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-isnull.lo -MD -MP -MF .deps/libuuid_la-isnull.Tpo -c isnull.c  -fPIC -DPIC -o .libs/libuuid_la-isnull.o
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-isnull.lo -MD -MP -MF .deps/libuuid_la-isnull.Tpo -c isnull.c -o libuuid_la-isnull.o >/dev/null 
    2>&1
    mv -f .deps/libuuid_la-isnull.Tpo .deps/libuuid_la-isnull.Plo
    /bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.    -I. -g -O2 -MT libuuid_la-
    pack.lo -MD -MP -MF .deps/libuuid_la-pack.Tpo -c -o libuuid_la-pack.lo `test -f 'pack.c' || echo './'`pack.c
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-
    pack.lo -MD -MP -MF .deps/libuuid_la-pack.Tpo -c pack.c  -fPIC -DPIC -o .libs/libuuid_la-pack.o
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-
    pack.lo -MD -MP -MF .deps/libuuid_la-pack.Tpo -c pack.c -o libuuid_la-pack.o >/dev/null 2>&1
    mv -f .deps/libuuid_la-
    pack.Tpo .deps/libuuid_la-pack.Plo
    /bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.    -I. -g -O2 -MT libuuid_la-parse.lo -MD -MP -MF .deps/libuuid_la-parse.Tpo -c -o libuuid_la-parse.lo `test -f 
    'parse.c' || echo './'`parse.c
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-parse.lo -MD -MP -MF .deps/libuuid_la-parse.Tpo -c parse.c  -fPIC -DPIC -o .libs/libuuid_la-parse.o
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-parse.lo -MD -MP -MF .deps/libuuid_la-parse.Tpo -c parse.c -o libuuid_la-parse.o >/dev/null 
    2>&1
    mv -f .deps/libuuid_la-parse.Tpo .deps/libuuid_la-parse.Plo
    /bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.    -I. -g -O2 -MT libuuid_la-
    unpack.lo -MD -MP -MF .deps/libuuid_la-unpack.Tpo -c -o libuuid_la-unpack.lo `test -f 'unpack.c' || echo './'`unpack.c
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-
    unpack.lo -MD -MP -MF .deps/libuuid_la-unpack.Tpo -c unpack.c  -fPIC -DPIC -o .libs/libuuid_la-unpack.o
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-
    unpack.lo -MD -MP -MF .deps/libuuid_la-unpack.Tpo -c unpack.c -o libuuid_la-unpack.o >/dev/null 2>&1
    mv -f .deps/libuuid_la-
    unpack.Tpo .deps/libuuid_la-unpack.Plo
    /bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.    -I. -g -O2 -MT libuuid_la-unparse.lo -MD -MP -MF .deps/libuuid_la-unparse.Tpo -c -o libuuid_la-unparse.lo `test -f 
    'unparse.c' || echo './'`unparse.c
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-unparse.lo -MD -MP -MF .deps/libuuid_la-unparse.Tpo -c unparse.c  -fPIC -DPIC -o .libs/libuuid_la-unparse.o
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-unparse.lo -MD -MP -MF .deps/libuuid_la-unparse.Tpo -c unparse.c -o libuuid_la-unparse.o >/dev/null 
    2>&1
    mv -f .deps/libuuid_la-unparse.Tpo .deps/libuuid_la-unparse.Plo
    /bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.    -I. -g -O2 -MT libuuid_la-uuid_time.lo -MD -MP -MF .deps/libuuid_la-uuid_time.Tpo -c -o libuuid_la-uuid_time.lo `test -f 
    'uuid_time.c' || echo './'`uuid_time.c
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-uuid_time.lo -MD -MP -MF .deps/libuuid_la-uuid_time.Tpo -c uuid_time.c  -fPIC -DPIC -o .libs/libuuid_la-uuid_time.o
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-uuid_time.lo -MD -MP -MF .deps/libuuid_la-uuid_time.Tpo -c uuid_time.c -o libuuid_la-uuid_time.o >/dev/null 
    2>&1
    mv -f .deps/libuuid_la-uuid_time.Tpo .deps/libuuid_la-uuid_time.Plo
    /bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.    -I. -g -O2 -MT libuuid_la-randutils.lo -MD -MP -MF .deps/libuuid_la-randutils.Tpo -c -o libuuid_la-randutils.lo `test -f 
    'randutils.c' || echo './'`randutils.c
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-randutils.lo -MD -MP -MF .deps/libuuid_la-randutils.Tpo -c randutils.c  -fPIC -DPIC -o .libs/libuuid_la-randutils.o
    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -g -O2 -MT libuuid_la-randutils.lo -MD -MP -MF .deps/libuuid_la-randutils.Tpo -c randutils.c -o libuuid_la-randutils.o >/dev/null 
    2>&1
    mv -f .deps/libuuid_la-randutils.Tpo .deps/libuuid_la-randutils.Plo
    /bin/bash ./libtool  --tag=CC   --mode=
    link gcc -I. -g -O2 -version-info 1:0:0  -o libuuid.la -rpath /usr/local/lib libuuid_la-clear.lo libuuid_la-compare.lo libuuid_la-copy.lo libuuid_la-gen_uuid.lo libuuid_la-isnull.lo libuuid_la-pack.lo libuuid_la-parse.lo libuuid_la-unpack.lo libuuid_la-unparse.lo libuuid_la-uuid_time.lo libuuid_la-randutils.lo   
    libtool: 
    link: gcc -shared  -fPIC -DPIC  .libs/libuuid_la-clear.o .libs/libuuid_la-compare.o .libs/libuuid_la-copy.o .libs/libuuid_la-gen_uuid.o .libs/libuuid_la-isnull.o .libs/libuuid_la-pack.o .libs/libuuid_la-parse.o .libs/libuuid_la-unpack.o .libs/libuuid_la-unparse.o .libs/libuuid_la-uuid_time.o .libs/libuuid_la-randutils.o    -O2   -Wl,-soname -Wl,libuuid.so.1 -o .libs/libuuid.so.1.0.0
    libtool: 
    link: (cd ".libs" && rm -f "libuuid.so.1" && ln -s "libuuid.so.1.0.0" "libuuid.so.1")
    libtool: 
    link: (cd ".libs" && rm -f "libuuid.so" && ln -s "libuuid.so.1.0.0" "libuuid.so")
    libtool: 
    link: ar cru .libs/libuuid.a  libuuid_la-clear.o libuuid_la-compare.o libuuid_la-copy.o libuuid_la-gen_uuid.o libuuid_la-isnull.o libuuid_la-pack.o libuuid_la-parse.o libuuid_la-unpack.o libuuid_la-unparse.o libuuid_la-uuid_time.o libuuid_la-randutils.o
    ar: `u
    ' modifier ignored since `D' is the default (see `U')
    libtool: link: ranlib .libs/libuuid.a
    libtool: 
    link: ( cd ".libs" && rm -f "libuuid.la" && ln -s "../libuuid.la" "libuuid.la" )
    make[
    1]: Leaving directory '/home/michael/git/libuuid-1.0.3'
    michael@ubuntu:~/git/libuuid-
    1.0.3$ make install
    make[
    1]: Entering directory '/home/michael/git/libuuid-1.0.3'
     /bin/
    mkdir -p '/usr/local/lib'
     /bin/bash ./libtool   --mode=install /usr/bin/install -c   libuuid.la 
    '/usr/local/lib'
    libtool: install: /usr/bin/install -c .libs/libuuid.so.
    1.0.0 /usr/local/lib/libuuid.so.1.0.0
    /usr/bin/install: cannot create regular file 
    '/usr/local/lib/libuuid.so.1.0.0': Permission denied
    make[
    1]: *** [Makefile:446: install-libLTLIBRARIES] Error 1
    make[
    1]: Leaving directory '/home/michael/git/libuuid-1.0.3'
    make: *** [Makefile:
    906: install-am] Error 2
    michael@ubuntu:~/git/libuuid-
    1.0.3$ sudo make install
    [sudo] password 
    for michael: 
    make[
    1]: Entering directory '/home/michael/git/libuuid-1.0.3'
     /bin/
    mkdir -p '/usr/local/lib'
     /bin/bash ./libtool   --mode=install /usr/bin/install -c   libuuid.la 
    '/usr/local/lib'
    libtool: install: /usr/bin/install -c .libs/libuuid.so.
    1.0.0 /usr/local/lib/libuuid.so.1.0.0
    libtool: install: (cd /usr/
    local/lib && { ln -s -f libuuid.so.1.0.0 libuuid.so.1 || { rm -f libuuid.so.1 && ln -s libuuid.so.1.0.0 libuuid.so.1; }; })
    libtool: install: (cd /usr/
    local/lib && { ln -s -f libuuid.so.1.0.0 libuuid.so || { rm -f libuuid.so && ln -s libuuid.so.1.0.0 libuuid.so; }; })
    libtool: install: /usr/bin/install -c .libs/libuuid.lai /usr/
    local/lib/libuuid.la
    libtool: install: /usr/bin/install -c .libs/libuuid.a /usr/
    local/lib/libuuid.a
    libtool: install: 
    chmod 644 /usr/local/lib/libuuid.a
    libtool: install: ranlib /usr/
    local/lib/libuuid.a
    libtool: finish: PATH=
    "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/sbin" ldconfig -n /usr/local/lib
    ----------------------------------------------------------------------
    Libraries have been installed in:
       /usr/
    local/lib

    If you ever happen to want to 
    link against installed libraries
    in a given directory, LIBDIR, you must either 
    use libtool, and
    specify the full pathname of the library, 
    or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH
    ' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH
    ' environment variable
         during linking
       - 
    use the `-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to `/etc/ld.so.conf'

    See any operating 
    system documentation about shared libraries for
    more information, such as the ld(
    1and ld.so(8) manual pages.
    ----------------------------------------------------------------------
     /bin/
    mkdir -p '/usr/local/lib/pkgconfig'
     /usr/bin/install -c -
    m 644 uuid.pc '/usr/local/lib/pkgconfig'
     /bin/
    mkdir -p '/usr/local/include/uuid'
     /usr/bin/install -c -
    m 644 uuid.h '/usr/local/include/uuid'
    make[
    1]: Leaving directory '/home/michael/git/libuuid-1.0.3'
    michael@ubuntu:~/git/libuuid-
    1.0.3$ ls
    aclocal.m4     gen_uuid.c              libuuid_la-
    pack.o        pack.c
    all-io.h       install-sh              libuuid_la-parse.lo      parse.c
    c.h            isnull.c                libuuid_la-parse.o       randutils.c
    clear.c        libtool                 libuuid_la-randutils.lo  randutils.h
    compare.c      libuuid.la              libuuid_la-randutils.o   stamp-h1
    config.guess   libuuid_la-clear.lo     libuuid_la-
    unpack.lo     test_uuid.c
    config.h       libuuid_la-clear.o      libuuid_la-
    unpack.o      unpack.c
    config.h.in    libuuid_la-compare.lo   libuuid_la-unparse.lo    unparse.c
    config.
    log     libuuid_la-compare.o    libuuid_la-unparse.o     uuidd.h
    config.status  libuuid_la-copy.lo      libuuid_la-uuid_time.lo  uuid.h
    config.
    sub     libuuid_la-copy.o       libuuid_la-uuid_time.o   uuid.pc
    configure      libuuid_la-gen_uuid.lo  ltmain.sh                uuid.pc.in
    configure.ac   libuuid_la-gen_uuid.o   Makefile                 uuidP.h
    copy.c         libuuid_la-isnull.lo    Makefile.am              uuid_time.c
    COPYING        libuuid_la-isnull.o     Makefile.in
    depcomp        libuuid_la-
    pack.lo      missing
    michael@ubuntu:~/git/libuuid-
    1.0.3$ vim ./test_uuid.c 
    michael@ubuntu:~/git/libuuid-
    1.0.3$ gcc test_uuid.c -o test_uuid
    /usr/bin/ld: /tmp/ccRUh9Vk.o: in function `test_uuid
    ':
    test_uuid.c:(.text+0x2d): undefined reference to `uuid_parse'
    /usr/bin/ld: /tmp/ccRUh9Vk.o: in function `main':
    test_uuid.c:(.text+0x10a): undefined reference to `uuid_generate'
    /usr/bin/ld: test_uuid.c:(.text+0x120): undefined reference to `uuid_unparse'
    /usr/bin/ld: test_uuid.c:(.text+0x1b7): undefined reference to `uuid_type'
    /usr/bin/ld: test_uuid.c:(.text+0x1cc): undefined reference to `uuid_variant'
    /usr/bin/ld: test_uuid.c:(.text+0x226): undefined reference to `uuid_generate_random'
    /usr/bin/ld: test_uuid.c:(.text+0x23c): undefined reference to `uuid_unparse'
    /usr/bin/ld: test_uuid.c:(.text+0x2d3): undefined reference to `uuid_type'
    /usr/bin/ld: test_uuid.c:(.text+0x2e8): undefined reference to `uuid_variant'
    /usr/bin/ld: test_uuid.c:(.text+0x35e): undefined reference to `uuid_generate_time'
    /usr/bin/ld: test_uuid.c:(.text+0x374): undefined reference to `uuid_unparse'
    /usr/bin/ld: test_uuid.c:(.text+0x40b): undefined reference to `uuid_type'
    /usr/bin/ld: test_uuid.c:(.text+0x420): undefined reference to `uuid_variant'
    /usr/bin/ld: test_uuid.c:(.text+0x4b1): undefined reference to `uuid_time'
    /usr/bin/ld: test_uuid.c:(.text+0x4ff): undefined reference to `uuid_parse'
    /usr/bin/ld: test_uuid.c:(.text+0x515): undefined reference to `uuid_compare'
    /usr/bin/ld: test_uuid.c:(.text+0x546): undefined reference to `uuid_clear'
    /usr/bin/ld: test_uuid.c:(.text+0x552): undefined reference to `uuid_is_null'
    /usr/bin/ld: test_uuid.c:(.text+0x58d): undefined reference to `uuid_copy'
    /usr/bin/ld: test_uuid.c:(.text+0x5a3): undefined reference to `uuid_compare'
    collect2: error: ld returned 1 exit status
    michael@ubuntu:~/git/libuuid-
    1.0.3$ cd /usr/local/lib
    michael@ubuntu:/usr/
    local/lib$ ls
    lib3ds-
    1.so.3      lib3ds.la  libuuid.la    libuuid.so.1.0.0  python3.6
    lib3ds-
    1.so.3.0.0  lib3ds.so  libuuid.so    pkgconfig
    lib3ds.a           libuuid.a  libuuid.so.
    1  python2.7
    michael@ubuntu:/usr/
    local/lib$ cd ~/git/libuuid-1.0.3/
    michael@ubuntu:~/git/libuuid-
    1.0.3$ gcc test_uuid.c -luuid -o test_uuid
    michael@ubuntu:~/git/libuuid-
    1.0.3$ ls
    aclocal.m4     gen_uuid.c              libuuid_la-
    pack.o        pack.c
    all-io.h       install-sh              libuuid_la-parse.lo      parse.c
    c.h            isnull.c                libuuid_la-parse.o       randutils.c
    clear.c        libtool                 libuuid_la-randutils.lo  randutils.h
    compare.c      libuuid.la              libuuid_la-randutils.o   stamp-h1
    config.guess   libuuid_la-clear.lo     libuuid_la-
    unpack.lo     test_uuid
    config.h       libuuid_la-clear.o      libuuid_la-
    unpack.o      test_uuid.c
    config.h.in    libuuid_la-compare.lo   libuuid_la-unparse.lo    
    unpack.c
    config.
    log     libuuid_la-compare.o    libuuid_la-unparse.o     unparse.c
    config.status  libuuid_la-copy.lo      libuuid_la-uuid_time.lo  uuidd.h
    config.
    sub     libuuid_la-copy.o       libuuid_la-uuid_time.o   uuid.h
    configure      libuuid_la-gen_uuid.lo  ltmain.sh                uuid.pc
    configure.ac   libuuid_la-gen_uuid.o   Makefile                 uuid.pc.in
    copy.c         libuuid_la-isnull.lo    Makefile.am              uuidP.h
    COPYING        libuuid_la-isnull.o     Makefile.in              uuid_time.c
    depcomp        libuuid_la-
    pack.lo      missing
    michael@ubuntu:~/git/libuuid-
    1.0.3$ ./test_uuid 
    UUID generate = 53ead8bd-e562-4e79-bf6a-4e7cbf4c331d
    UUID: 53ead8bde5624e79bf6a4e7cbf4c331d
    UUID type = 
    4, UUID variant = 1

    UUID random string = dacba404-
    2350-47c3-b8de-f451f843b849
    UUID: dacba404235047c3b8def451f843b849
    UUID type = 
    4, UUID variant = 1

    UUID string = 6c7dffbe-d07d-11e9-9d41-000c2977e04e
    UUID 
    time: 6c7dffbed07d11e99d41000c2977e04e
    UUID type = 
    1, UUID variant = 1
    UUID 
    time is: (1567757272119699): Fri Sep  6 16:07:52 2019

    UUID parse 
    and compare succeeded.
    UUID clear 
    and is null succeeded.
    UUID copy 
    and compare succeeded.
    84949cc5-
    4701-4a84-895b-354c584a981b is valid, OK
    84949CC5-
    4701-4A84-895B-354C584A981B is valid, OK
    84949cc5-
    4701-4a84-895b-354c584a981bc is invalid, OK
    84949cc5-
    4701-4a84-895b-354c584a981 is invalid, OK
    84949cc5x4701-4a84-895b-354c584a981b is invalid, OK
    84949cc504701-4a84-895b-354c584a981b is invalid, OK
    84949cc5-470104a84-895b-354c584a981b is invalid, OK
    84949cc5-
    4701-4a840895b-354c584a981b is invalid, OK
    84949cc5-
    4701-4a84-895b0354c584a981b is invalid, OK
    g4949cc5-
    4701-4a84-895b-354c584a981b is invalid, OK
    84949cc5-
    4701-4a84-895b-354c584a981g is invalid, OK
    michael@ubuntu:~/git/libuuid-
    1.0.3$ 

      

    • crossguid

      

      crossguid则为我们提供了CMakeLists.txt,方便我们使用cmake的方式来构建,构建成功后会生成一个libcrossguid.a 静态库和测试程序 crossguid-test ,全部的终端执行如下:

     Shell Code 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
     
    michael@ubuntu:~$ cd ./git/crossguid-master/
    michael@ubuntu:~/git/crossguid-master$ ls
    android     cmake           crossguid.pc.in  LICENSE    src
    android.sh  CMakeLists.txt  include          README.md  test
    michael@ubuntu:~/git/crossguid-master$ mkdir build
    michael@ubuntu:~/git/crossguid-master$ cd ./build/
    michael@ubuntu:~/git/crossguid-master/build$ cmake --version
    cmake version 
    3.12.1

    CMake suite maintained 
    and supported by Kitware (kitware.com/cmake).
    michael@ubuntu:~/git/crossguid-master/build$ cmake ..
    -- The C compiler identification 
    is GNU 8.2.0
    -- The CXX compiler identification 
    is GNU 8.2.0
    -- Check 
    for working C compiler: /usr/bin/cc
    -- Check 
    for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C 
    compile features
    -- Detecting C 
    compile features - done
    -- Check 
    for working CXX compiler: /usr/bin/c++
    -- Check 
    for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX 
    compile features
    -- Detecting CXX 
    compile features - done
    -- Found PkgConfig: /usr/
    bin/pkg-config (found version "0.29.1"
    -- Found LibUUID: /usr/lib/x86_64-linux-gnu/libuuid.so (found version 
    "2.32.0"
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/michael/git/crossguid-master/build
    michael@ubuntu:~/git/crossguid-master/build$ make
    Scanning dependencies of target crossguid
    20%] Building CXX object CMakeFiles/crossguid.dir/src/guid.cpp.o
    40%] Linking CXX static library libcrossguid.a
    40%] Built target crossguid
    Scanning dependencies of target crossguid-test
    60%] Building CXX object CMakeFiles/crossguid-test.dir/test/TestMain.cpp.o
    80%] Building CXX object CMakeFiles/crossguid-test.dir/test/Test.cpp.o
    [
    100%] Linking CXX executable crossguid-test
    [
    100%] Built target crossguid-test
    michael@ubuntu:~/git/crossguid-master/build$ make install
    40%] Built target crossguid
    [
    100%] Built target crossguid-test
    Install the project...
    -- Install configuration: 
    "Release"
    -- Installing: /usr/local/lib/libcrossguid.a
    CMake Error at cmake_install.cmake:
    41 (file):
      
    file INSTALL cannot copy file
      
    "/home/michael/git/crossguid-master/build/libcrossguid.a" to
      
    "/usr/local/lib/libcrossguid.a".


    make: *** [Makefile:
    118: install] Error 1
    michael@ubuntu:~/git/crossguid-master/build$ ls
    CMakeCache.txt  cmake_install.cmake  crossguid-test  Makefile
    CMakeFiles      crossguid.pc         libcrossguid.a
    michael@ubuntu:~/git/crossguid-master/build$ ./crossguid-test 
    66ea935c-730c-
    4518-82b3-f12424544a5b
    73cecead-39c4-
    4942-8a7e-029df3629f28
    82aea220-ad0b-41d7-8c83-668a31fdcb47
    All tests passed!
    michael@ubuntu:~/git/crossguid-master/build$ 

      具体函数使用请参考官方文档,本文到此为止。

  • 相关阅读:
    ZeroMQ自查手册
    如何回答——请简述MySQL索引类型
    101. 对称二叉树
    66. 加一
    104. 二叉树的最大深度
    724.寻找数组的中心索引
    33. 搜索旋转排序数组
    快速排序
    Vue
    HTML
  • 原文地址:https://www.cnblogs.com/MakeView660/p/11475604.html
Copyright © 2020-2023  润新知