【发布时间】:2021-07-04 11:12:56
【问题描述】:
我正在尝试创建一个跨平台应用程序 (Linux/Windows),它使用第三方依赖项,例如 jsoncpp。在 Linux 上我使用 cmake,在 Windows 上我使用 Visual Studio + Conan。存在一个问题,即 cpp 标头的路径在不同的操作系统上有所不同。在 Linux 上,我像这样包含 jsoncpp:
#include <jsoncpp/json/config.h>
#include <jsoncpp/json/value.h>
但在 Windows 上我必须使用其他方式:
#include <json/config.h>
#include <json/value.h>
在 Windows 上,柯南一路安装标头(没有 jsoncpp 前缀):
C:\Users\User\.conan\data\jsoncpp\1.9.0\theirix\stable\package\3fb49604f9c2f729b85ba3115852006824e72cab\include\json
conaninfo.txt 文件内容:
[requires]
jsoncpp/1.9.0@theirix/stable
[generators]
MSBuildDeps
有一种方法可以使用包含路径,比如在 Linux 上?没有这么丑陋的代码:
#ifdef __linux__
#include <jsoncpp/json/config.h>
#include <jsoncpp/json/value.h>
#else
#include <json/config.h>
#include <json/value.h>
#endif
【问题讨论】:
标签: visual-studio cmake conan