0

I installed libxml2 and am using to compile a sample file that reads an xml document. I use the following to flags so I am using the libxml2:

gcc `xml2-config --cflags xml2-config --libs` libxml.c 

However it crashes right on the first line of parsing the file:

Error: <unknown>:1: syntax error near line 1
context: <?xml version="1.0" >>>  encoding="UTF-8"?> <<< 
Segmentation fault

I know that it is a valid xml file, the first couple of lines of the xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" level="3" version="1">
  <model metaid="_case00010" id="case00010" name="case00010" timeUnits="time">

Does any one had this error before? Thanks.

This is what I get when running gdb but am not sure what it means:

Cannot find new threads: generic error

The code is verbatim from here: http://www.xmlsoft.org/examples/parse1.c

And the xml file passes a validation check.

mihajlv
  • 2,275
  • 4
  • 36
  • 59
  • 1
    Why do you think it is libxml2 crash? Maybe it is your program, which does not handle the error properly? – fork0 Aug 05 '12 at 15:49
  • Did you check to see whether the XML file is indeed encoded in UTF-8? – Kevin Mangold Aug 05 '12 at 15:50
  • @fork0 my mistake, it is not a libxml2 crash, I meant to say it doesn't parse a valid xml file. – mihajlv Aug 05 '12 at 15:51
  • Well, it does parse it (I just tried) here, and AFAICS it is almost valid (not DTD, but it is not fatal), so it can be something specific to you system... What does `xml2-config --version` say? – fork0 Aug 05 '12 at 15:55
  • @KevinMangold `file -bi filename` gives me that the file is xml but charset = us-ascii. I did `iconv -f us-ascii -t UTF-8` but I still get us-ascii. – mihajlv Aug 05 '12 at 16:02
  • @mihajlv us-ascii is a full subset of UTF-8 – fork0 Aug 05 '12 at 16:04
  • @mihajlv can you validate your xml using the online XML validator? http://www.xmlvalidation.com/ – fork0 Aug 05 '12 at 16:05
  • @fork0 I did it works. I posted above the error when running gdb but am not sure what it means. – mihajlv Aug 05 '12 at 16:08
  • Can we see your code? I suspect you've corrupted the input when reading it before passing it to libxml... – R.. GitHub STOP HELPING ICE Aug 05 '12 at 16:16
  • @R.. the code is verbatim from here http://www.xmlsoft.org/examples/parse1.c – mihajlv Aug 05 '12 at 16:19
  • Looks like you just have a very (very! 2.7.2 is from 2008) old libxml2, then. Though I cannot see where even this version could find an error in that data. Any unusual line-endings in it, perhaps? CR/LF, oder CR only? – fork0 Aug 05 '12 at 16:33
  • @fork0 Ok I find the error and I don't know why would make a diffrence. I changed the compilation to: `gcc `xml2-config --cflags` libxml.c `xml2-config --libs` that is I put the linkage info at the end and it worked. It is interesting how it compiled before. – mihajlv Aug 05 '12 at 16:38

1 Answers1

0

For some reason it is not linking right the libraries when the file name is at the end. I put the linkage info at the end and it wokred:

gcc 'xml2-config --cflags' libxml.c 'xml2-config --libs'

mihajlv
  • 2,275
  • 4
  • 36
  • 59
  • I cannot understand how it compiled at all. The command in the question, as given can't work: it misses the backticks character between the `--cflags` and `--libs` commands to get the flags. So you couldn't get the libraries at all. The miracle it compiled might be explained you have the symbols of libxml2 elsewhere in the command (an error, easy to make in an IDE or build system bloated enough). – fork0 Aug 05 '12 at 16:59