首页 > 解决方案 > 包含 jsoncpp 后编译错误

问题描述

当我尝试构建测试源时,我得到一个类似的错误。

stl_tree.h:542:14: 错误: '__node' 没有命名类型 ::new(__node) _Rb_tree_node<_Val>;

执行者的内容。

#include <CppUTest/TestHarness.h>
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/UtestMacros.h>
#include <CppUTestExt/MockSupport.h>

int main(int argc, char** argv) {
  MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
  return CommandLineTestRunner::RunAllTests(argc, argv);
}

我的测试的源代码以以下包括开头。

#include <CppUTest/TestHarness.h>
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/UtestMacros.h>
#include <CppUTestExt/MockSupport.h>
#include <iostream>
#include "common/data_util_astro_cfg.h"

TEST_GROUP(ASTRO_UTIL_TEST) {
  void setup() { }
  void teardown() { }
};

“common/data_util_astro_cfg.h”文件包含以下内容。

#include "../data/data_type_file.h"
#include <json/json.h>

static AstroConfigs toAstroConfigs(std::string content)

我的问题是我得到了这些包含的编译错误,当我删除行 json.h include 一切都很好我可以获得二进制输出。

我认为问题在于新运营商的冲突。该解决方案由 Cpputest 方提供,位于http://cpputest.github.io/manual.html#memory_leak_detection。但不知何故还不清楚。:(

包含 <map> 后,该问题已在编译错误中定义。它与我的非常相似,但问题已通过创建新项目解决。在那种情况下,我别无选择。我正在使用 Yocto 项目,该项目也使用自动生成工具创建。

你能帮我解决这个问题吗?(感谢您的时间。)

标签: c++compiler-errorscpputest

解决方案


不幸的是,我在一段时间后解决了这个问题。CPPUTest 似乎有问题。在测试文件的顶部,我有几个包含。其中一些属于 CPPUTest 库,其中一些是我的。我的包含在 CPPUTest 之后,这就是我收到错误的原因。如果我改变他们的位置,它将正常工作。这似乎毫无意义,但却是正确的解决方案。“应该通过在包含列表底部定义 CPPUTEST 库来解决问题。”</p>


推荐阅读