2014-02-08 55 views
2

我正在使用Code Blocks IDE为Windows编写C++应用程序。我有兴趣使用以下XML ++库:http://libxmlplusplus.sourceforge.net/使用CodeBlocks IDE for C++链接libxml ++和glib库的问题Windows

它需要libxml2和glibmm-2.4库。我通过右键单击“Build Options”==>“Search Directories”选项卡==>“Compiler”选项卡,为每个这些库下载源代码并将所有头文件包括到我的项目中。我在那里指定了头文件包含文件。我使用xml ++/examples目录下的“examples/dom_parser”的源代码修改了main.cpp文件。

现在,我遇到以下错误消息的问题。我之前从未“链接”或使用过* .lib,* .dll文件,但现在我收到以下“未定义参考”错误消息。请让我知道我需要做什么来建立这个。是否有需要“链接”的特定文件?如果有,这些文件位于何处?我似乎无法在我提取的源文件中找到它们。你能帮助具体说明哪些文件包含在哪些文件夹中?我正在使用CodeBlocks IDE。

有人可以复制您的Windows 64位PC上的项目,看看它是否能够正确运行?

谢谢。

UPDATE

C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:44: undefined reference to `xmlpp::ContentNode::is_white_space() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:47: undefined reference to `xmlpp::Node::get_name() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:49: undefined reference to `Glib::ustring::empty() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:53: undefined reference to `xmlpp::Node::get_namespace_prefix() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:54: undefined reference to `Glib::ustring::empty() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:55: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:57: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:57: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:57: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:69: undefined reference to `xmlpp::ContentNode::get_content() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:69: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:69: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:74: undefined reference to `xmlpp::ContentNode::get_content() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:74: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:74: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:79: undefined reference to `xmlpp::ContentNode::get_content() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:79: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:79: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:87: undefined reference to `xmlpp::Node::get_line() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:90: undefined reference to `xmlpp::Element::get_attributes() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:96: undefined reference to `xmlpp::Node::get_namespace_prefix() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:97: undefined reference to `Glib::ustring::empty() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `xmlpp::Attribute::get_value() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `xmlpp::Attribute::get_name() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `xmlpp::Attribute::get_value() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `xmlpp::Attribute::get_name() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:101: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `Glib::ustring::ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `Glib::ustring::ustring(char const*)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `xmlpp::Element::get_attribute(Glib::ustring const&, Glib::ustring const&) const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:106: undefined reference to `xmlpp::Attribute::get_value() const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:106: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:106: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:113: undefined reference to `Glib::ustring::ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:113: undefined reference to `xmlpp::Node::get_children(Glib::ustring const&) const' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:113: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:118: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:57: undefined reference to `Glib::ustring::~ustring()' 
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:69: undefined reference to `Glib::ustring::~ustring()' 

**已更新2014年2月11日 - 在上午10:45 **

嗨。感谢您的建议。我最终下载了以下(http://ftp.gnome.org/pub/gnome/binaries/win32/gtkmm/2.22/)整个gtkmm-win32-devel-2.22.0-2.exe,并将它安装到C:\ gtkmm中的Windows PC上。然后,我通过包含头文件,库文件和bin文件来修改我的项目。下面是截图:

enter image description here

enter image description here

enter image description here

enter image description here

建设,我现在看到的是0错误和0警告消息后。但是,它似乎是CRASH。我不知道为什么。看来,gtk安装使用libxml ++版本2.6。这可以。我从网站上下载了libxml ++ 2.6来查看它们提供的示例。我在main.cc中使用了以下源代码。你知道什么是问题吗?

// -*- C++ -*- 

/* main.cc 
* 
* Copyright (C) 2002 The libxml++ development team 
* 
* This library is free software; you can redistribute it and/or 
* modify it under the terms of the GNU Library General Public 
* License as published by the Free Software Foundation; either 
* version 2 of the License, or (at your option) any later version. 
* 
* This library is distributed in the hope that it will be useful, 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
* Library General Public License for more details. 
* 
* You should have received a copy of the GNU Library General Public 
* License along with this library; if not, write to the Free 
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
*/ 

#ifdef HAVE_CONFIG_H 
#include <config.h> 
#endif 

#include <libxml++/libxml++.h> 

#include <iostream> 

void print_indentation(unsigned int indentation) 
{ 
    for(unsigned int i = 0; i < indentation; ++i) 
    std::cout << " "; 
} 

void print_node(const xmlpp::Node* node, unsigned int indentation = 0) 
{ 
    std::cout << std::endl; //Separate nodes by an empty line. 

    const xmlpp::ContentNode* nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node); 
    const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(node); 
    const xmlpp::CommentNode* nodeComment = dynamic_cast<const xmlpp::CommentNode*>(node); 

    if(nodeText && nodeText->is_white_space()) //Let's ignore the indenting - you don't always want to do this. 
    return; 

    Glib::ustring nodename = node->get_name(); 

    if(!nodeText && !nodeComment && !nodename.empty()) //Let's not say "name: text". 
    { 
    print_indentation(indentation); 
    std::cout << "Node name = " << node->get_name() << std::endl; 
    std::cout << "Node name = " << nodename << std::endl; 
    } 
    else if(nodeText) //Let's say when it's text. - e.g. let's say what that white space is. 
    { 
    print_indentation(indentation); 
    std::cout << "Text Node" << std::endl; 
    } 

    //Treat the various node types differently: 
    if(nodeText) 
    { 
    print_indentation(indentation); 
    std::cout << "text = \"" << nodeText->get_content() << "\"" << std::endl; 
    } 
    else if(nodeComment) 
    { 
    print_indentation(indentation); 
    std::cout << "comment = " << nodeComment->get_content() << std::endl; 
    } 
    else if(nodeContent) 
    { 
    print_indentation(indentation); 
    std::cout << "content = " << nodeContent->get_content() << std::endl; 
    } 
    else if(const xmlpp::Element* nodeElement = dynamic_cast<const xmlpp::Element*>(node)) 
    { 
    //A normal Element node: 

    //line() works only for ElementNodes. 
    print_indentation(indentation); 
    std::cout << "  line = " << node->get_line() << std::endl; 

    //Print attributes: 
    const xmlpp::Element::AttributeList& attributes = nodeElement->get_attributes(); 
    for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) 
    { 
     const xmlpp::Attribute* attribute = *iter; 
     print_indentation(indentation); 
     std::cout << " Attribute " << attribute->get_name() << " = " << attribute->get_value() << std::endl; 
    } 

    const xmlpp::Attribute* attribute = nodeElement->get_attribute("title"); 
    if(attribute) 
    { 
     std::cout << "title found: =" << attribute->get_value() << std::endl; 

    } 
    } 

    if(!nodeContent) 
    { 
    //Recurse through child nodes: 
    xmlpp::Node::NodeList list = node->get_children(); 
    for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter) 
    { 
     print_node(*iter, indentation + 2); //recursive 
    } 
    } 
} 

int main(int argc, char* argv[]) 
{ 
    Glib::ustring filepath; 
    if(argc > 1) 
    filepath = argv[1]; //Allow the user to specify a different XML file to parse. 
    else 
    filepath = "example.xml"; 

    try 
    { 
    xmlpp::DomParser parser; 
    parser.set_validate(); 
    parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically. 
    parser.parse_file(filepath); 
    if(parser) 
    { 
     //Walk the tree: 
     const xmlpp::Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser. 
     print_node(pNode); 
    } 
    } 
    catch(const std::exception& ex) 
    { 
    std::cout << "Exception caught: " << ex.what() << std::endl; 
    } 

    return 0; 
} 
+0

确保您已安装并链接到所有必需的依赖项(libxml2,glibmm-2.4)。 – Aleph

+0

我为(libxml ++,libxml2和glibmm-2.4)添加了每个包含/头文件,但是现在我看到了“未定义的引用”错误消息。我似乎无法找到这些库的“库”/“链接器”文件。你知道这些文件的名称和它们所在的目录吗?我更新了我的原始帖子,并提供了错误消息 – codeshark

回答

2

libxml2glibmm-2.4是否构建?

您可以找到libxml2here的预编译窗口二进制文件。我无法找到glibmm的预构建窗口二进制文件,因此您必须下载整个gtkmminstaller或。

这个过程完成后,你应该有文件,如

libxml2.lib 
libxml2.a 
libxml2.dll 

取决于你的编译器(GCC或MSVC),以及所需的连接方法(静态或动态),你应该选择所需的库文件。

在Code :: Blocks中,通过“链接器设置”选项卡进行链接,可通过Project -> Build options... -> Linker settings访问。点击add并使用文件夹浏览器选择以前编译的 库文件(libxml2glibmm-2.4libxml++)。

更新:我可以在我的Windows 8 64位个人电脑上成功运行该项目。

我有一个从MinGW-builds(GCC 4.8.1)安装的MinGW-64。我唯一需要下载的其他东西是gtkmm-win64 installer。我选择了“完全安装”。

在项目生成设置的搜索目录是:

C:\gtkmm64\include 
C:\gtkmm64\include\libxml++-2.6 
C:\gtkmm64\include\glibmm-2.4 
C:\gtkmm64\include\glib-2.0 
C:\gtkmm64\lib\glibmm-2.4\include 
C:\gtkmm64\lib\glib-2.0\include 
C:\gtkmm64\lib\libxml++-2.6\include 

的导入库链接为:

C:\gtkmm64\lib\libxml++-2.6.dll.a 
C:\gtkmm64\lib\libglibmm-2.4.dll.a 
C:\gtkmm64\lib\libglibmm_generate_extra_defs-2.4.dll.a 

和DLL的复制到从gtkmm64\bin文件夹中的可执行文件的位置分别为:

libglib-2.0-0.dll 
libglibmm-2.4-1.dll 
libglibmm_generate_extra_defs-2.4-1.dll 
libxml++-2.6-2.dll 
libxml2-2.dll 

可执行文件成功运行(exc由于某些解析异常,导致程序终止的事实)。

+0

感谢您的建议。请参阅我上面的更新文章。我添加了屏幕截图和我的代码。我下载了整个gtkmm安装程序并将其安装到我的Windows PC上。它现在能够用0错误和0警告来构建,但现在我看到它崩溃了。你知道可能是什么问题吗?你能复制这个吗? – codeshark

+0

现在看来它甚至不能执行第一行:“Glib :: ustring filepath;” – codeshark

+0

据我所知,'.dll.a'文件是*导入库*,而不是*静态库*。它们不包含实际功能,只包含调用动态库函数的存根。尝试链接到'libglibmm-2.4.a'和'libxml ++ - 2.6.a'。 –