HP和RedHat上可以使用uuidgen來生成,solaris上命令:makeuuid
如何通過C++編程取得UUID?
1.安裝libuuid庫, libuuid.so.1包涵在e2fsprogs裡,本人的系統為RedHat7.3,下載ftp://194.199.20.114/linux/redhat/7.3/en/os/i386/RedHat/RPMS/e2fsprogs-1.27-3.i386.rpm
2. 編輯文件uuid.cpp
復制代碼代碼如下:
#include <iostream>;
#include <stdio.h>;
#include <uuid/uuid.h>;
int main()
{
uuid_t uu;
uuid_generate( uu );
std::cout << uu << std::endl;
int i;
for(i=0;i<16;i++)
{
printf("%x ",uu);
}
printf("\n");
return 0;
}
#g++ -c –g uuid.o uuid.cpp
#g++ -o –luuid uuid uuid.o
其中/usr/include/uuid/uuid.h中有uuid_t的定義:
typedef unsigned char uuid_t[16];