我正在尝试在hello世界中使用spdlog库。
#include "spdlog/spdlog.h" int main() { return 0; }
|+ hello.cpp |+ spdlog | |+ spdlog.h |+common.h .....
但当我建造 gcc hello.cpp
gcc hello.cpp
我得到: spdlog/spdlog.h:10:10: fatal error: spdlog/common.h: No such file or directory #include "spdlog/common.h" 问题是spdlog库中的每个地方都引用spdlog文件夹下的文件。在上面的错误示例中,spdlog.h包含同一文件夹中的common.h。但包括如下内容: #include "spdlog/common.h" 为什么“spdlog”在所有头的include中都加了前缀?
spdlog/spdlog.h:10:10: fatal error: spdlog/common.h: No such file or directory #include "spdlog/common.h"
#include "spdlog/common.h"
由于您的头文件路径是spdlog/.h,所以您应该提供spdlog文件夹所在的路径。喜欢
gcc -c -I/<Path of spdlog parent folder> hello.cpp