• C

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

ChartTrackAsked:
Who is Participating?
 
brettmjohnsonCommented:
> ANSIC C

Obviously, I meant ANSI C
0
 
Infinity08Commented:
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);

    /* ... */

}
0
 
ChartTrackAuthor Commented:
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
0
WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

 
Infinity08Commented:
You've got to add the library to your linker settings (check the project options).
0
 
ChartTrackAuthor Commented:
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
0
 
Infinity08Commented:
Is this a C or C++ library ?

Did you try a different compiler ?
0
 
brettmjohnsonCommented:
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.

0
 
ChartTrackAuthor Commented:
We have success!!!!
My old compiler came up trumps......

Thanks for your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.