LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Expat XML Parser not working (https://www.linuxquestions.org/questions/linux-software-2/expat-xml-parser-not-working-597157/)

itsmilesdavis 11-04-2007 09:24 PM

Expat XML Parser not working
 
First off, I'm running Ubuntu 7.04

I installed Expat 2.0.1 from
http://sourceforge.net/projects/expat/

'./configure'
and
'sudo make install'

It seemed to install alright. I saw no errors or anything

However, when I try to compile the sample problem from (there is a link to a zip file with the .c files [line.c, etc.])
http://www.xml.com/pub/a/1999/09/exp...ex.html?page=2

All breaks loose:

line.c:21:22: error: xmlparse.h: No such file or directory
line.c:37: error: expected ‘)’ before ‘p’
line.c: In function ‘start_hndl’:
line.c:47: error: ‘XML_Parser’ undeclared (first use in this function)
line.c:47: error: (Each undeclared identifier is reported only once
line.c:47: error: for each function it appears in.)
line.c:47: error: expected ‘)’ before ‘data’
line.c: In function ‘proc_hndl’:
line.c:65: error: ‘XML_Parser’ undeclared (first use in this function)
line.c:65: error: expected ‘)’ before ‘data’
line.c: In function ‘main’:
line.c:70: error: ‘XML_Parser’ undeclared (first use in this function)
line.c:70: error: expected ‘;’ before ‘p’
line.c:71: error: ‘p’ undeclared (first use in this function)
line.c:73: warning: incompatible implicit declaration of built-in function ‘exit’
line.c:87: warning: incompatible implicit declaration of built-in function ‘strlen’
line.c:90: warning: incompatible implicit declaration of built-in function ‘exit’
line.c:97: warning: incompatible implicit declaration of built-in function ‘exit’
line.c:69: warning: return type of ‘main’ is not ‘int’

It would appear that my expat install was unsuccessful? Or, maybe I need to add something to my path? Can anyone off any advice?

matthewg42 11-06-2007 06:01 AM

Why don't you install from the repositories? Compiling from source is sometimes necessary, but if there is a pre-built package, you should probably use it.

The expat package is found in the universe repository, so you need to enable that and then reload the package list.
  • Open synaptic package manager, go to the Settings menu, select Repositories.
  • Check "community maintained (universe)
  • Close the dialog. You will get a message saying "Repositories changed", click close/OK
  • Click the reload button on the toolbar
  • Search for expat
  • Click the box to the left of the expat package and select "mark for installation". You will probably be told that other packages will also be marked. That's fine, but don't worry if there is no notification.
  • Click apply on the toolbarm, confir, apply in dialog
  • Wait for installation, and close synaptic.

itsmilesdavis 11-06-2007 09:56 PM

Reinstalled expat...still no good.
 
expat was already installed according to the Repository. I marked for reinstallation and applied it. The reinstall went fine.

However, the code still does not work. Same errors I mentioned from above.

Could something be missing in my path?

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

matthewg42 11-07-2007 01:36 AM

Oh I see now. I had mis-understood youd initial post to mean you were trying to build the expat library itself. My apologies - I didn't read as thoroughly as I should have.

The expat package only contains the xmlwf program and attendant files. If you want to build software which uses the expat library, you should install the package libexpat-dev. You will also need the regular development tools. Most of these are provided by the package build-essential. I think you probably have this installed already if you have gcc available.

matthewg42 11-07-2007 02:23 AM

I looked at the examples in the .zip file from that page. It looks like since they were written the usage of the expat library has changed and the examples will not build.

The libexpat-dev is actually a virtual package which installs libexpat1-dev. If you list the files in this package, you will find these:
Code:

dpkg --listfiles libexpat1-dev |grep example
/usr/share/doc/libexpat1-dev/examples
/usr/share/doc/libexpat1-dev/examples/elements.c
/usr/share/doc/libexpat1-dev/examples/outline.c
/usr/share/doc/libexpat1-dev/examples/elements.dsp.gz
/usr/share/doc/libexpat1-dev/examples/outline.dsp.gz

There is no Makefile, but these samples are trivial to build:
Code:

mkdir $HOME/expat_examples
cd $HOME/expat_examples
cp /usr/share/doc/libexpat1-dev/examples/*.c .
gcc elements.c -lexpat -o elements
gcc outline.c -lexpat -o outline

Hope that helps.

itsmilesdavis 11-14-2007 11:53 AM

more issues
 
I followed your directions (thank you for taking time with this issue, by the way), but it I'm still having issues.

I have the following packages installed (through Synaptic Package Manager):
expat
libexpat1
libexpat1-dev

(also, build-essential)

I copied the examples you described in the last post, 'elements.c' and 'outline.c'. However, I still have issues.

jr@Deimos:~/Desktop/expat_examples$ cp /usr/share/doc/libexpat1-dev/examples/*.c .
jr@Deimos:~/Desktop/expat_examples$ ls
elements.c outline.c
jr@Deimos:~/Desktop/expat_examples$ gcc elements.c
/tmp/cc0Bi17J.o: In function `main':
elements.c:(.text+0x95): undefined reference to `XML_ParserCreate'
elements.c:(.text+0xbd): undefined reference to `XML_SetUserData'
elements.c:(.text+0xdb): undefined reference to `XML_SetElementHandler'
elements.c:(.text+0x14a): undefined reference to `XML_Parse'
elements.c:(.text+0x15c): undefined reference to `XML_GetCurrentLineNumber'
elements.c:(.text+0x16c): undefined reference to `XML_GetErrorCode'
elements.c:(.text+0x174): undefined reference to `XML_ErrorString'
elements.c:(.text+0x1b9): undefined reference to `XML_ParserFree'
collect2: ld returned 1 exit status
jr@Deimos:~/Desktop/expat_examples$ gcc outline.c
/tmp/ccCL5zbl.o: In function `main':
outline.c:(.text+0xcc): undefined reference to `XML_ParserCreate'
outline.c:(.text+0x121): undefined reference to `XML_SetElementHandler'
outline.c:(.text+0x1bc): undefined reference to `XML_Parse'
outline.c:(.text+0x1cb): undefined reference to `XML_GetErrorCode'
outline.c:(.text+0x1d3): undefined reference to `XML_ErrorString'
outline.c:(.text+0x1e0): undefined reference to `XML_GetCurrentLineNumber'
collect2: ld returned 1 exit status

matthewg42 11-18-2007 12:17 PM

You forgot the -lexpat option when using gcc.

Also, you do not need to perform a manual link stage invoking ld - gcc will do this for you.

Code:

gcc elements.c -lexpat -o elements


All times are GMT -5. The time now is 05:39 AM.