剥离所有不必要的代码后,这是拒绝编译的准系统版本:
#include <iostream>
#include <libxml++/libxml++.h>
using namespace std;
int main (int argc, char *argv[]) {
cout << "Hello, World!" << endl;
return 0;
}
我使用的是 Fedora 16 的最新版本。最初,编译器甚至找不到 libml++/libxml++.h,因为 Fedora 的 yum 将这些文件放在/usr/include/libxml++-2.6/libxml++。所以我通过创建符号链接(symbolic link)/usr/include/libxml++ 到/usr/include/libxml++-2.6/libxml++ 来解决这个问题。这阻止了编译器提示找不到 libxml++.h,但是在 libxml++.h 中有一行
#include <ustring.h>
编译器再次找不到。因此,我再次创建了一个从/usr/include/glibmm 到/usr/include/glibmm-2.4/glibmm 的符号链接(symbolic link),这是 ustring.h 实际所在的位置。
现在编译器已经停止提示 ustring.h,但是 ustring.h 中的第一行(实际)是
#include <glibmmconfig.h>
编译器找不到。
glibmmconfig.h的实际位置是/usr/lib64/glibmm-2.4/include。但我不想更改 ustring.h。
有没有办法不用经常创建符号链接(symbolic link)等来解决我的问题?
预先感谢您的帮助。
编辑
我能够使用以下编译器选项解决我的问题:
`pkg-config --cflags --libs glibmm-2.4 libxml++-2.6`
感谢 jpalecek 指出了方向,但我不得不寻找更多的东西,直到我能够解决我的问题。
但是当这些编译器选项编译上面的简单程序时,它们无法编译关于 libxml++ tutorial page 的教程。 :
#include <iostream>
#include <libxml++/libxml++.h>
#include <string.h>
using namespace std;
int main (int argc, char *argv[]) {
string FilePath = "SampleXMLDocument.xml";
try {
xmlpp::DomParser Parser;
Parser.set_substitute_entities ();
Parser.parse_file (FilePath);
cout << "Successfully parsed XML file" << endl;
} catch (const exception& excp) {
cout << "Exception caught: " << excp.what () << endl;
}
return 0;
} // End main ()
这次我得到了一堆错误,如下所示:
undefined reference to `xmlpp::DomParser::DomParser()`
undefined reference to `xmlpp::Parser::set_substitute_entities(bool)`
等等。
我想我的搜索还在继续。
最佳答案
您必须将正确的选项传递给编译器,尤其是正确的包含路径。包装商通过一个为您提供选项的程序使这成为可能:xml++-config --cflags
将为您提供 -Ipath_to_headers
、xml++-config --libs
会给你 -lto_link
。
关于c++ - 无法编译使用 libxml++ 的简单程序,因为找不到 glibmmconfig.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10237651/