spdlog是一个header file only日志库,使用起来非常方便,所以打算引入到自己的工程里。然而在使用过程中出现了Fatal Error C1083错误,错误的位置定位到了spdlog的包含文件上:
#include <spdlog/sinks/base_sink.h>
#include <spdlog/details/file_helper.h>
#include <spdlog/details/null_mutex.h>
#include <spdlog/details/synchronous_factory.h>
但是这些文件确确实实的就在这些路径下。经过摸索,当把上述包含头文件的方式改为用双引号时,错误居然消失了:
#include "spdlog/sinks/base_sink.h"
#include "spdlog/details/file_helper.h"
#include "spdlog/details/null_mutex.h"
#include "spdlog/details/synchronous_factory.h"
最终在微软官方文档(Fatal Error C1083 | Microsoft Docs)发现这样一个说明:
意思就是如果你的你要引用的头文件在你工程源文件目录的子目录中,那么必须使用双引号引用你的头文件,使用<>引用会出现C1083错误。
为了不修改spdlog的原始文件,找到了一个解决方法:既然spdlog在工程源文件目录中不行,那就放到其他目录下,比如工程源文件目录的上级目录,然后在附加包含目录中将这个路径引入,这样错误就消失了。