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;i16;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];