gpt4 book ai didi

c++ - 不能在 cmake_pch.h 中包含标准库

转载 作者:行者123 更新时间:2023-12-05 01:28:43 25 4
gpt4 key购买 nike

我正在尝试在 cmake 中生成一个预编译 header ,其中包含我经常使用的标准库。当我运行 cmake 时没有错误,但是当我构建它时它说它无法在 cmake_pch.h 中找到 header 。

这是添加预编译 header 的 cmake 脚本片段:

target_precompile_headers(fae-core PRIVATE
<algorithm>
<cstddef>
<fstream>
<string>
<sstream>
<memory>
<chrono>
)

这是运行 cmake 生成的 makefile 的完整输出:

Scanning dependencies of target fae-core
[ 6%] Building CXX object core/CMakeFiles/fae-core.dir/cmake_pch.hxx.gch
[ 12%] Building C object core/CMakeFiles/fae-core.dir/cmake_pch.h.gch
In file included from <command-line>:32:
/home/finn/dev/fae/build/core/CMakeFiles/fae-core.dir/cmake_pch.h:4:10: fatal error: algorithm: No such file or directory
4 | #include <algorithm>
| ^~~~~~~~~~~
compilation terminated.
make[2]: *** [core/CMakeFiles/fae-core.dir/build.make:78: core/CMakeFiles/fae-core.dir/cmake_pch.h.gch] Error 1
make[1]: *** [CMakeFiles/Makefile2:136: core/CMakeFiles/fae-core.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

我只包含了我的 cmake 代码中与 pch 相关的部分,因为我之前只是将 libs 直接包含在我的 src 文件中并且一切正常,所以我认为它纯粹与 pch 相关。如果有帮助,我很乐意编辑和添加我的其余脚本。

最佳答案

您已将 C++ header 添加到您的 target_precompile_headers 命令,而且还向您的目标添加了 C 源代码。这是行不通的,因为 C 编译器不理解如何包含 C++ 标准头文件。查看错误信息:

[ 12%] 构建 C 对象 core/CMakeFiles/fae-core.dir/cmake_pch.h.gch

从目标中删除 C++ header 或为 C 和 C++ 源定义单独的目标。

关于c++ - 不能在 cmake_pch.h 中包含标准库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68392702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com