【问题标题】:Compilation errors with RapidXMLRapidXML 的编译错误
【发布时间】:2010-04-04 18:04:32
【问题描述】:

我是 rapidXML 的新手,但第一印象并不积极,我制作了简单的 Visual Studio 6 C++ Hello World 应用程序并将 RapidXML hpp 文件添加到项目中,并在 main.cpp 中放入:

#include "stdafx.h"

#include < iostream >
#include < string >
#include "rapidxml.hpp"

using namespace std;
using namespace rapidxml;

int main ( )
{
    char x[] = "<Something>Text</Something>\0" ; //<<<< funktioniert, aber mit '*' nicht
    xml_document<> doc ;
    doc.parse<0>(x) ;
    cout << "Name of my first node is: " << doc.first_node()->name() << endl ;
    xml_node<>* node = doc.first_node("Something") ;
    cout << "Node 'Something' has value: " << node->value() << endl ;
} 

它不能编译,有什么帮助吗? RapidXML 是否可以与 Visual Studio 6 一起运行? 我得到的错误是:

--------------------Configuration: aaa - Win32 Debug--------------------
Compiling...
rapidxml.cpp
c:\Parser\rapidxml.cpp(310) : error C2039: 'size_t' : is not a member of 'std'
c:\Parser\rapidxml.cpp(320) : error C2039: 'size_t' : is not a member of 'std'
c:\Parser\rapidxml.cpp(320) : error C2039: 'size_t' : is not a member of 'std'
c:\Parser\rapidxml.cpp(385) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled
c:\Parser\rapidxml.cpp(417) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled
c:\Parser\rapidxml.cpp(417) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled
c:\Parser\rapidxml.cpp(448) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled
c:\Parser\rapidxml.cpp(448) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled
c:\Parser\rapidxml.cpp(476) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled
c:\Parser\rapidxml.cpp(579) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled
c:\Parser\rapidxml.cpp(599) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled
c:\Parser\rapidxml.cpp(681) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled
c:\Parser\rapidxml.cpp(700) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled
c:\Parser\rapidxml.cpp(721) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled
c:\Parser\rapidxml.cpp(751) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled
c:\Parser\rapidxml.cpp(786) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled
c:\Parser\rapidxml.cpp(787) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled
c:\Parser\rapidxml.cpp(836) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(876) : see reference to class template instantiation 'rapidxml::xml_attribute<Ch>' being compiled
c:\Parser\rapidxml.cpp(856) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(876) : see reference to class template instantiation 'rapidxml::xml_attribute<Ch>' being compiled
c:\Parser\rapidxml.cpp(936) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled
c:\Parser\rapidxml.cpp(958) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled
c:\Parser\rapidxml.cpp(981) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled
c:\Parser\rapidxml.cpp(1004) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled
c:\Parser\rapidxml.cpp(1025) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled
c:\Parser\rapidxml.cpp(1045) : error C2039: 'size_t' : is not a member of 'std'
        c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled
Error executing cl.exe.

rapidxml.obj - 25 error(s), 0 warning(s)

【问题讨论】:

  • 目前,Boost 库使用 rapidxml 作为 XML 解析器。如果您愿意,可以查看 Boost Code。

标签: c++ rapidxml


【解决方案1】:

我刚刚注意到您的错误与 rapidxml.cpp 有关。 那个文件是从哪里来的??

RapidXML 是一个只有头文件的库。没有rapidxml.cpp,并且rapidxml.hpp 不能单独编译 - 您只需将其包含在您自己的文件中(如上面的main.cpp)即可使用它。

我对 VC++ 一无所知,但请尝试从 VC 项目中删除“rapidxml”并重新构建。

【讨论】:

  • 我在 cpp 中重命名了 rapidxml.hpp 是不是错了?最后应该用相同的编译器编译,对吧?我从 main.cpp 中删除了“使用命名空间 rapidxml;”正如您所说,但仍然出现错误:删除项目“RapidXMLParser - Win32 调试”的中间文件和输出文件。 --------------------配置:RapidXMLParser - Win32 调试-------------------- 正在编译... main.cpp c:_milan\tools\rapidxmlparser\rapidxml.hpp(312) : error C2039: 'size_t' : is not a member of 'std' c:_milan\tools\rapidxmlparser\rapidxml.hpp(322) : error C2039 : 'size_t' : 不是'std'的成员
  • @milan: “我在 cpp 中重命名了 rapidxml.hpp 是不是错了?”是的。 100% 错误。 它只是一个头文件。这就是你所需要的。 “删除 rapidxml”是指 *从 VS 项目中删除文件 rapidxml.cpp,而不是删除“使用命名空间 rapidxml”行。
  • 现在可以编译,但是主文件中的函数:doc.first_node()->name() 给出异常(访问冲突)。当我调试函数中发生异常时: Ch *name() const { return m_name ? m_name : nullstr();调试器中的变量 m_name 显示以下值: m_name CXX0030:错误:无法评估表达式 任何线索在这个简单的情况下有什么问题?兄弟,米兰。
【解决方案2】:

Visual C++ 6 可以追溯到 C++ 语言标准化之前。如果您在用它编译甚至模糊的现代代码时遇到问题,那么问题可能出在编译器而不是代码上。此类问题通常无法修复 - 您可能需要升级到更现代的编译器。

【讨论】:

  • 由于我只是这个 parsig 业务的新手,我确实希望这是我的错误......让我们看看其他人的想法。
  • @milan 错误是VC++ 6.0显然无法编译RapidXM,与你自己的codeL无关。鉴于 RapidXML 项目在 VC++ 6 发布 8 年后开始,这并不奇怪。 “其他人”怎么想并不重要。
  • 获得新的 Visual Studio 需要付出代价......所以我宁愿等待任何其他意见 :)
  • 我仍然没有检查,但我得到的信息就像你尼尔告诉我的那样..编译器似乎太旧了。
【解决方案3】:

这在技术上是不合法的,但您可以尝试在您的 #include "rapidxml.hpp" 行上方插入以下代码:

namespace std
{
    typedef unsigned long size_t;
}

这将在 RapidXML 尝试使用之前(非法)将 size_t 注入到 std 命名空间中。如果真的可以编译,那么你可以搜索VC6的头文件,找出size_t的真正定义是什么,然后替换上面的unsigned long

【讨论】:

  • 我不允许发送完整的错误列表,但我得到了这个(我把你说的先放在 main 然后放在 rapidxml.hpp 文件中): rapidxml.cpp rapidxml_iterators.cpp c:_milan\tools \aaa\rapidxml_iterators.cpp(24) : error C2039: 'ptrdiff_t' : is not a member of 'std' c:_milan\tools\aaa\rapidxml_iterators.cpp(91) : see reference to class template instantiation 'rapidxml:: node_iterator' 正在编译
  • 我认为ptrdiff_t 可能与size_t 相同。将另一个 typedef 添加到您的命名空间,然后重试。
猜你喜欢
  • 2012-07-21
  • 1970-01-01
  • 2013-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-04
相关资源
最近更新 更多