You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编译bpftime时出现<chrono>头文件找不到的错误求助

解决bpftime项目编译时<chrono>头文件找不到的问题

问题背景

构建bpftime项目时,代码中使用#include <chrono>触发编译错误:

fatal error: include/chrono: No such file or directory    14 | #include <chrono>

使用的编译器版本:

pegasus@pegasus:~$ clang --version
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 815644b4dd882ade2e5649d4f97c3dd6f7aea200)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/pegasus/Documents/llvm-project/build/bin
pegasus@pegasus:~$ g++ --version
g++ (Ubuntu 13.2.0-4ubuntu3) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

pegasus@pegasus:~$ gcc --version
gcc (Ubuntu 13.2.0-4ubuntu3) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

构建命令为make release JOBS=$(nproc),项目Makefile中已指定CXXFLAGS += -std=c++17。

问题分析

<chrono>是C++11及以上标准库的核心头文件,报错原因通常是以下几点:

  • CMake未正确启用C++17标准,导致编译器未加载对应标准库
  • 自定义编译的clang未关联系统标准库(如libstdc++),无法找到头文件
  • 旧的CMake缓存覆盖了编译参数

解决方案

1. 强制CMake启用C++17标准

修改Makefile中release目标的cmake命令,显式添加C++标准参数:

release: ## build the release version
    cmake -Bbuild  -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \
                   -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO \
                   -DCMAKE_CXX_STANDARD=17 \
                   -DCMAKE_CXX_STANDARD_REQUIRED=ON
    cmake --build build --config RelWithDebInfo --target install  -j$(JOBS)

2. 指定clang使用系统libstdc++标准库

如果自定义编译的clang默认使用libc++(而系统未安装完整libc++),需强制指定使用libstdc++:
在cmake命令中添加CMAKE_CXX_FLAGS参数:

release: ## build the release version
    cmake -Bbuild  -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \
                   -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO \
                   -DCMAKE_CXX_STANDARD=17 \
                   -DCMAKE_CXX_STANDARD_REQUIRED=ON \
                   -DCMAKE_CXX_FLAGS="-stdlib=libstdc++"
    cmake --build build --config RelWithDebInfo --target install  -j$(JOBS)

3. 清理缓存后重建

执行清理命令清除旧的构建缓存,再重新构建:

make clean
make release JOBS=$(nproc)

内容的提问来源于stack exchange,提问作者NobinPegasus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 20:56:03