I've been trying to use the XML parser tinyxml-2 (textproc/tinyxml2), but I can only link to it statically. If I try linking to the shared object my program crashes with a "segmentation fault" error.
Here are the compiling commands and application output:
Here are the contents of the source and XML file, just in case.
test.cpp:
test.xml:
Please let me know if anyone else is having the same problem. I have filed a bug report: PR 194375. I believe that the problem affects both textproc/tinyxml2 and textproc/tinyxml, though I have only tested it thoroughly with tinyxml2.
My system:
Here are the compiling commands and application output:
Code:
$ ls
test.cpp test.xml
$ g++ test.cpp -o test -ltinyxml2
$ ./test test.xml
Segmentation fault (core dumped)
$ g++ test.cpp -o test /usr/local/lib/libtinyxml2.a
$ ./test test.xml
Loading XML contents....
sword
Loaded.
Here are the contents of the source and XML file, just in case.
test.cpp:
Code:
#include <tinyxml2.h>
using namespace tinyxml2;
#include <iostream>
using namespace std;
int loadXML(char* filename) {
XMLDocument doc;
doc.LoadFile(filename);
XMLElement* titleElement = doc.FirstChildElement("items")->FirstChildElement("item")->FirstChildElement("name");
cout << titleElement->GetText() << endl;
return doc.ErrorID();
}
int main(int argc, char* argv[]) {
// Load XML contents
cout << "Loading XML contents....\n";
if (argc > 1) {
loadXML(argv[1]);
cout << "Loaded.\n";
} else {
cout << "Must specify an XML file... exiting.\n";
return 1;
}
return 0;
}
test.xml:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<items>
<!-- WEAPONS -->
<item category="weapon">
<name>sword</name>
<icon>sword</icon>
<attributes>
<stat label="strength" value="1" />
</attributes>
</item>
<!-- CONSUMABLES -->
<item category="consumable">
<name>milk</name>
<icon>milk</icon>
<attributes>
<regen label="health" value="5" />
</attributes>
</item>
<item category="consumable">
<name>bacon</name>
<icon>bacon</icon>
<attributes>
<regen label="health" value="2" />
</attributes>
</item>
</items>
Please let me know if anyone else is having the same problem. I have filed a bug report: PR 194375. I believe that the problem affects both textproc/tinyxml2 and textproc/tinyxml, though I have only tested it thoroughly with tinyxml2.
My system:
- FreeBSD 10.0-RELEASE r260789 amd64
- gcc/g++ 4.7.4 (FreeBSD Ports Collection)
- tinyxml2 20140112