这是用户在 2025-1-24 10:22 为 https://github.com/lfreist/hwinfo 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
Skip to content
/ hwinfo Public

cross platform C++ library for hardware information (CPU, RAM, GPU, ...)
用于硬件信息(CPU、RAM、GPU 等)的跨平台 C++ 库

License

Notifications You must be signed in to change notification settings

lfreist/hwinfo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

894ed64 · Dec 26, 2024
Jul 24, 2024
Aug 31, 2024
Oct 15, 2024
Oct 15, 2024
Jul 24, 2024
Dec 26, 2024
Oct 12, 2023
Nov 28, 2022
Jul 8, 2024
Jul 25, 2024
Oct 15, 2024
Aug 23, 2022
Oct 13, 2024
Jun 22, 2023

Repository files navigation

Linux (clang) Linux (gcc)

MacOS

Windows (Visual Studio)

clang format

hwinfo  HWINFO 公司

hwinfo provides an easy-to-use and modern C++ API for retrieving hardware information of your systems components such as CPU, RAM, GPU, Disks, Mainboard, ...
hwinfo 提供了一个易于使用且现代的 C++ API,用于检索系统组件的硬件信息,例如 CPU、RAM、GPU、磁盘、主板等。

Note  注意

If you face any issues, find bugs or if your platform is not supported yet, do not hesitate to create an issue.
如果您遇到任何问题、发现错误或您的平台尚不受支持,请不要犹豫,创建一个问题

Content  内容

Supported Components  支持的组件

Note  注意

The listed components that are not yet implemented (indicated with ❌) are in development and will be supported in future releases. You are welcome to start contributing and help improving this library!
列出的尚未实现的组件(用 ❌ 表示)正在开发中,将来的版本将支持这些组件。欢迎您开始贡献并帮助改进此库!

Component  元件 Info  信息 Linux  Linux的 Apple  苹果 Windows  窗户
CPU Vendor  供应商 ✔️ ❌️ ✔️
Model ✔️ ✔️ ✔️
Frequency  频率 ✔️ ❌️ ✔️
Physical Cores  物理内核 ✔️ ✔️ ✔️
Logical Cores  逻辑内核 ✔️ ✔️ ✔️
Cache Size  缓存大小 ✔️ ❌️ ✔️
GPU Vendor  供应商 ✔️ ❌️ ✔️
Model ✔️ ❌️ ✔️
Memory Size  内存大小 ✔️
Memory (RAM)  内存 (RAM) Vendor  供应商 ✔️
Model ✔️
Name  名字 ✔️
Serial Number  序号 ✔️
Total Memory Size  总内存大小 ✔️ ✔️ ✔️
Free Memory Size  可用内存大小 ✔️ ✔️
Mainboard  主板 Vendor  供应商 ✔️ ✔️
Model ✔️ ✔️
Version  版本 ✔️ ✔️
Serial-Number  序列号 ✔️
Bios  生物
Disk  磁盘 Vendor  供应商 ✔️ ✔️ ✔️
Model ✔️ ✔️ ✔️
Serial-Number  序列号 ✔️ ✔️ ✔️
Size  大小 ✔️ ✔️ ✔️
Operating System  操作系统 Name  名字 ✔️ ✔️ ✔️
Short Name  简称 ✔️ ❌️ ✔️
Version  版本 ✔️ ✔️
Kernel  内核 ✔️ ✔️
Architecture (Bit)  架构 (Bit) ✔️ ✔️ ✔️
Endianess  Endianess (循序浅) ✔️ ✔️ ✔️
Battery  电池 Vendor  供应商 ✔️ ❌️
Model ✔️
Serial Number  序号 ✔️ ✔️
Technology  科技 ✔️
Capacity  能力 ✔️ ✔️ ️❌
Charging  充电 ✔️ ✔️

All components are available via the hwinfo::hwinfo target, or via individual CMake targets, which you can choose and link against depending on your needs.
所有组件都可以通过 hwinfo::hwinfo 目标或通过单个 CMake 目标获得,您可以根据需要选择和链接这些目标。

target_link_libraries(your_target PRIVATE hwinfo::hwinfo)

or  

target_link_libraries(
  your_target
  PRIVATE hwinfo::cpu
          hwinfo::gpu
          hwinfo::ram
          hwinfo::mainboard
          hwinfo::disk
          hwinfo::os
          hwinfo::battery)

The CMake options control which components will be built and available in the library:
CMake 选项控制哪些组件将被构建并在库中可用:

  • HWINFO_OS "Enable OS detection" (default to ON)
    HWINFO_OS“启用操作系统检测”(默认为 ON)
  • HWINFO_MAINBOARD "Enable mainboard detection" (default to ON)
    HWINFO_MAINBOARD“启用主板检测”(默认为 ON)
  • HWINFO_CPU "Enable CPU detection" (default to ON)
    HWINFO_CPU“启用 CPU 检测”(默认为 ON)
  • HWINFO_DISK "Enable disk detection" (default to ON)
    HWINFO_DISK“启用磁盘检测”(默认为 ON)
  • HWINFO_RAM "Enable RAM detection" (default to ON)
    HWINFO_RAM“启用 RAM 检测”(默认为 ON)
  • HWINFO_GPU "Enable GPU detection" (default to ON)
    HWINFO_GPU“启用 GPU 检测”(默认为 ON)
  • HWINFO_GPU_OPENCL "Enable usage of OpenCL in GPU information" (default to OFF)
    HWINFO_GPU_OPENCL“Enable use of OpenCL in GPU information”(在 GPU 信息中启用 OpenCL)(默认为 OFF)
  • HWINFO_BATTERY "Enable battery detection" (default to ON)
    HWINFO_BATTERY“启用电池检测”(默认为 ON)

Build hwinfo  构建 hwinfo

Requirements: git, cmake, c++ compiler (gcc, clang, MSVC)
要求:git、cmake、c++ 编译器(gcc、clang、MSVC)

  1. Download repository:   下载仓库:
    git clone https://github.com/lfreist/hwinfo
    
  2. Build using cmake:   使用 cmake 构建:
    mkdir build
    cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES=Release
    cmake --build build --config Release
    This builds static and dynamic libraries. Static library cmake targets are named <target>_static (e.g. hwinfo_static)
    这将构建静态和动态库。静态库 cmake 目标命名为 <target>_static (例如 hwinfo_static

Example  

See system_infoMain.cpp
查看 system_infoMain.cpp

The output should look similar to this one:
输出应类似于以下内容:

Hardware Report:

----------------------------------- CPU -----------------------------------
Socket 0:
 vendor:            GenuineIntel
 model:             Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz
 physical cores:    8
 logical cores:     16
 max frequency:     3792
 regular frequency: 3792
 min frequency:     -1
 current frequency: 3792
 cache size:        16777216
----------------------------------- OS ------------------------------------
Operating System:   Microsoft Windows 11 Professional (build 22621)
short name:         Windows
version:            <unknown>
kernel:             <unknown>
architecture:       64 bit
endianess:          little endian
----------------------------------- GPU -----------------------------------
GPU 0:
  vendor:           NVIDIA
  model:            NVIDIA GeForce RTX 3070 Ti
  driverVersion:    31.0.15.2698
  memory [MiB]:     8190
  min frequency:    0
  cur frequency:    0
  max frequency:    0
----------------------------------- RAM -----------------------------------
vendor:             Corsair
model:              CMK32GX4M2Z3600C18
name:               Physical Memory
serial-number:      ***
size [MiB]:         65437
free [MiB]:         54405
available [MiB]:    54405
------------------------------- Main Board --------------------------------
vendor:             ASUSTeK COMPUTER INC.
name:               PRIME Z490-A
version:            Rev 1.xx
serial-number:      ***
------------------------------- Batteries ---------------------------------
No Batteries installed or detected
--------------------------------- Disks -----------------------------------
Disk 0:
  vendor:           (Standard disk drives)
  model:            WD_BLACK SN850 Heatsink 1TB
  serial-number:    ***.
  size:             1000202273280
Disk 1:
  vendor:           (Standard disk drives)
  model:            Intenso SSD Sata III
  serial-number:    ***
  size:             120031511040
Disk 2:
  vendor:           (Standard disk drives)
  model:            KINGSTON SA400S37240G
  serial-number:    ***
  size:             240054796800
Disk 3:
  vendor:           (Standard disk drives)
  model:            WDS500G3X0C-00SJG0
  serial-number:    ***.
  size:             500105249280
Disk 4:
  vendor:           (Standard disk drives)
  model:            ST750LM022 HN-M750MBB
  serial-number:    ***
  size:             750153761280
---------------------------------------------------------------------------

include hwinfo to cmake project
将 HWINFO 包含在 CMake 项目中

Include installed version

  1. Install hwinfo   安装 hwinfo
    git clone https://github.com/lfreist/hwinfo && cd hwinfo
    mkdir build
    cmake -B build && cmake --build build
    cmake --install build
    
  2. Simply add the following to your CMakeLists.txt file:
    只需将以下内容添加到您的 CMakeLists.txt 文件中即可:
    # file: CMakeLists.txt
    
    find_package(hwinfo REQUIRED)
  3. Include hwinfo into your .cpp/.h files:
    hwinfo 包含在 .cpp/.h 文件中:
    // file: your_executable.cpp
    
    #include <hwinfo/hwinfo.h>
    
    int main(int argc, char** argv) {
     // Your code
    }
  4. Link it in cmake   在 cmake 中链接它
    add_executable(your_executable your_executable.cpp)
    target_link_libraries(your_executable PUBLIC lfreist-hwinfo::hwinfo)

As git submodule

  1. Download hwinfo into your project (e.g. in <project-root>/third_party/hwinfo)
    hwinfo 下载到您的项目中(例如在 <project-root>/third_party/hwinfo
    mkdir third_party
    cd third_party
    git clone https://github.com/lfreist/hwinfo
    
  2. Simply add the following to your <project-root>/CMakeLists.txt file:
    只需将以下内容添加到您的 <project-root>/CMakeLists.txt 文件中:
    # file: <project-root>/CMakeLists.txt
    
    # define the HWINFO_* options if you want to change the default values
    
    add_subdirectory(third_party/hwinfo)
  3. Include hwinfo into your .cpp/.h files:
    hwinfo 包含在 .cpp/.h 文件中:
    // file: your_executable.cpp
    
    #include "hwinfo/hwinfo.h"
    
    int main(int argc, char** argv) {
     // Your code
    }
  4. Link it in cmake   在 cmake 中链接它
    add_executable(your_executable your_executable.cpp)
    target_link_libraries(your_executable PUBLIC lfreist-hwinfo::hwinfo)