• 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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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);

    /* ... */

}
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
Infinity08Commented:
You've got to add the library to your linker settings (check the project options).
Prepare for an Exciting Career in Cybersecurity

Help prevent cyber-threats and provide solutions to safeguard our global digital economy. Earn your MS in Cybersecurity. WGU’s MSCSIA degree program curriculum features two internationally recognized certifications from the EC-Council at no additional time or cost.

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
Infinity08Commented:
Is this a C or C++ library ?

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

brettmjohnsonCommented:
> ANSIC C

Obviously, I meant ANSI C

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ChartTrackAuthor Commented:
We have success!!!!
My old compiler came up trumps......

Thanks for your help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.