C++ boost生成uuid 1. CMakeLists.txt文件 cmake_minimum_required(VERSION 3.12) project(UUID) set(CMAKE_CXX_STANDARD 14) find_package(Boost REQUIRED) message(STATUS "Find Boost include at ${Boost_INCLUDE_DIRS}") message(STATUS "Find Boost libraries: ${Boost_LIBRARIES}") add_executable(UUID main.cpp) 2. main.cpp文件 #include <iostream> #include <boost/uuid/uuid_io.hpp> #include <boost/uuid/uuid_generators.hpp> int main() { boost::uuids::uuid a_uuid = boost::uuids::random_generator()(); std::string uuid_string = boost::uuids::to_string(a_uuid); std::cout << uuid_string << std::endl; return 0; } 3.使用 mkdir build && cd buildcmake ..make -j./UUID