# MyTinySTL **Repository Path**: Saborking/my-tiny-stl ## Basic Information - **Project Name**: MyTinySTL - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-03-28 - **Last Updated**: 2025-04-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MyTinySTL ## 项目构建指南 ### 前置条件 在运行项目之前,需要选择以下其中一种方式安装 Google Test 框架: #### 方式一:使用包管理器安装 ```bash # 安装 GTest sudo apt-get update sudo apt-get install libgtest-dev ``` #### 方式二:通过 CMake FetchContent 下载 如果不想使用系统 GTest 或者没有 root 权限,可以使用这种方式。步骤如下: 1. 打开 `test/CMakeLists.txt` 2. 找到并取消注释以下代码段: ```cmake 下载并构建GoogleTest include(FetchContent) FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip DOWNLOAD_EXTRACT_TIMESTAMP true ) FetchContent_MakeAvailable(googletest) ``` 3. 注释掉 `find_package(GTest REQUIRED)` 这一行 这种方式会在构建时自动下载和编译 Google Test。 ### 构建步骤 1. 创建并进入构建目录: ```bash mkdir build cd build ``` 2. 生成构建文件: ```bash cmake .. ``` 3. 编译项目: ```bash # 编译所有文件 cmake --build . # 编译指定测试文件(例如 vector 测试) cmake --build . --target test_vector ``` 4. 运行测试: ```bash # 运行所有测试 ctest --verbose # 运行指定测试的方法: # 方法1:使用 ctest(推荐) ctest -R test_vector -V # -R 指定测试名称,-V 显示详细输出 # 方法2:直接运行可执行文件 ./test_vector # Linux/MacOS .\test_vector.exe # Windows ``` ### 注意事项 - 如果遇到 GTest 相关的包含路径错误,请确保已正确安装 GTest - 如果不想使用系统 GTest,可以在 test/CMakeLists.txt 中取消注释 FetchContent 相关代码,使用在线下载的方式 - 在 Windows 系统中,可执行文件可能在 `build/Debug/` 或 `build/Release/` 目录下 - 使用 ctest 运行测试时,确保 CMakeLists.txt 中已添加 `add_test` 命令