0

After stripping away all of the unnecessary code, this is the barebones version that refuses to compile:

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

using namespace std;

int main (int argc, char *argv[]) {
    cout << "Hello, World!" << endl;
    return 0;
}

I'm using an up-to-the-minute version of Fedora 16. Initially, the compiler could not find even libml++/libxml++.h, because Fedora's yum puts these files in /usr/include/libxml++-2.6/libxml++. So I got around that by creating the symlink /usr/include/libxml++ to /usr/include/libxml++-2.6/libxml++. That stopped the compiler from complaining about not finding libxml++.h, but then, in libxml++.h there is the line

#include <ustring.h>

which again the compiler could not find. So once again I created a symlink from /usr/include/glibmm to /usr/include/glibmm-2.4/glibmm, which is where ustring.h actually resides.

Now the compiler has stopped complaining about ustring.h, but the first (actual) line in ustring.h is

#include <glibmmconfig.h>

which the compiler cannot find.

The actual location of glibmmconfig.h is /usr/lib64/glibmm-2.4/include. But I would prefer not to alter ustring.h.

Is there a way out of my problems without constantly having to create symlinks, etc.?

Thanks in advance for your help.

EDIT

I was able to get around my problems with the following compiler options:

`pkg-config --cflags --libs glibmm-2.4 libxml++-2.6`

Thanks to jpalecek for pointing the way, but I had to hunt some more until I was able to get around my problem.

But while these compiler options compile the simple programme above, they fail to compile the tutorial on the 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 ()

This time I get a bunch of errors like the following:

undefined reference to `xmlpp::DomParser::DomParser()`
undefined reference to `xmlpp::Parser::set_substitute_entities(bool)`

and so on.

I guess my search continues.

Shredderroy
  • 2,860
  • 2
  • 29
  • 53
  • Which platform / distribution are you using? – sinelaw Apr 19 '12 at 22:21
  • Fedora 16, as mentioned in the post. The output of "uname -a" is "Linux localhost.localdomain 3.3.2-1.fc16.x86_64 #1 SMP Sat Apr 14 00:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux" – Shredderroy Apr 19 '12 at 22:22
  • What about add the path to your libraries? for example, path=...;path_to_your_h_files. I don't know if it works or I will post it as an answer – YankeeWhiskey Apr 19 '12 at 23:39
  • About the edit: Isn't your problem similar to this: http://stackoverflow.com/q/10200868/51831? Try that solution and see if it helps. – jpalecek Apr 20 '12 at 09:15
  • You edited to say that you are now using `pkg-config --cflags --libs glibmm-2.4 libxml++-2.6`. Note that you don't need to mention glibmm-2.4. Just mentioning libxml++-2.6 will take care of that for you. But I don't know why you still have those linker errors. – murrayc Apr 20 '12 at 14:30

3 Answers3

1

You must pass correct options to the compiler, particularly a correct include path. The packagers have made that possible by a program that gives you the options: xml++-config --cflags will give you -Ipath_to_headers, xml++-config --libs will give you -lto_link.

jpalecek
  • 47,058
  • 7
  • 102
  • 144
0

well i am not familiar with Fedora 16 but i think u got some link errors because libxml++ cannot be found. 1. check /usr/lib/ and other possible dirs that libxml++.so(maybe this name...) may locates. Make sure /etc/ld.so.conf contains this path so link can find it. If not, try to add the location of libxml++ and run "ldconfig" to update. 2. check the usage of -l option with the g++ is correct...

xgwang
  • 614
  • 7
  • 21
0

The easiest way to compile a library depending on libxml++-X.X is to use pkg-config:

c++ -std=c++11 -Wall $(pkg-config --cflags --libs libxml++-2.6) -o test main.cc

Specifying just libxml++-2.6 will resolve the glibmm-2.4 dependencies as well.

Joe
  • 56,979
  • 9
  • 128
  • 135