?
Solved

Trouble compiling with Expat

Posted on 2006-04-27
8
Medium Priority
?
505 Views
Last Modified: 2008-01-09
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

0
Comment
Question by:ChartTrack
  • 3
  • 3
  • 2
8 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 16551610
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
 

Author Comment

by:ChartTrack
ID: 16551629
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 16551982
You've got to add the library to your linker settings (check the project options).
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ChartTrack
ID: 16554524
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 16555379
Is this a C or C++ library ?

Did you try a different compiler ?
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 16555841
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
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 500 total points
ID: 16555854
> ANSIC C

Obviously, I meant ANSI C
0
 

Author Comment

by:ChartTrack
ID: 16560338
We have success!!!!
My old compiler came up trumps......

Thanks for your help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question