Link to home
Start Free TrialLog in
Avatar of ChartTrack
ChartTrack

asked on

Trouble compiling with Expat

Hi

I need to create a program to parse an XML file. I'm trying to us Expat, but have been having problems compiling my program.
I'm sure it's either a minor set-up problem or my old version of Microsoft Developer Studio 97 that I am using.

The code I am trouble with is:

#include<stdio.h>
#include<expat.h>


FILE *f_in;

int main(int argc, char* argv[])
{
      
      /* open log file in append mode */
      f_in = fopen("c:\\xml\test.xml","a+");
      if(f_in == NULL)
      {
            printf("Error opening log file");
      }

    XML_Parser p = XML_ParserCreate(NULL);


        /* close file */
      if(f_in) fclose(f_in);

      return 0;
}

As you can see I haven't got very far!!

The errors I get are:

C:\XML\XML.c(20) : error C2275: 'XML_Parser' : illegal use of this type as an expression
C:\XML\XML.c(20) : error C2146: syntax error : missing ';' before identifier 'p'
C:\XML\XML.c(20) : error C2065: 'p' : undeclared identifier
C:\XML\XML.c(20) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct XML_ParserStruct *'

I'm probably be very dim. But your help would be appreciated.

Thanks in advance

Andy

Avatar of Infinity08
Infinity08
Flag of Belgium image

See if the following changes to main help :

int main(int argc, char* argv[])
{
     XML_Parser p;                                       /* <----- moved the declaration to the beginning */

     /* open log file in append mode */
     f_in = fopen("c:\\xml\\test.xml","a+");    /* <-----  extra '\' added */
     if(f_in == NULL)
     {
          printf("Error opening log file");
     }

    p = XML_ParserCreate(NULL);

    /* ... */

}
Avatar of ChartTrack
ChartTrack

ASKER

That seems to work, thanks

Just got some linking errors.

XML.obj : error LNK2001: unresolved external symbol __imp__XML_ParserCreate
Debug/XML.exe : fatal error LNK1120: 1 unresolved externals

Which I am sure are down to my set up
You've got to add the library to your linker settings (check the project options).
Hmm weird.
I've downloaded versions 2, 1.9.8 & 1.9.1 of expat and get the following error all the time

C:\EXPAT-2.0.0\LIBS\libexpat.lib : fatal error LNK1106: invalid file or disk full: cannot seek to 0x43c49272
Error executing link.exe.

Surely all the files aren't corrupt!!!

Thanks for your help so far

Andy
Is this a C or C++ library ?

Did you try a different compiler ?
expat is ANSIC C (not C++ although there are C++ bindings for it).
It is likely the shipped library was created using modern linker that
probably supports (and uses) some feature that your 10 year old
linker does not understand.  It is quite likely you may need to
recompile the library from source using your old tools.

ASKER CERTIFIED SOLUTION
Avatar of brettmjohnson
brettmjohnson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
We have success!!!!
My old compiler came up trumps......

Thanks for your help