You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Jason Jesso <jj...@global-matrix.com> on 2001/09/05 15:00:48 UTC
XERCES-C in C programs
Hi:
Can XERCES-C be used in C programs, even though it is C++? Are there C
bindings?
Thanks
Jason
---------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org
Re: XERCES-C in C programs
Posted by Bob Jamison <rj...@lincom-asg.com>.
Jason Jesso wrote:
>Would this work if I compiled with a C compiler?
>
>Thanks
>Jason
>
Well, of course you will need C++ for the API "glue" file
between C and C++. But once compiled to an object or DLL
or lib or whatever, C programs should be able to link with it
just fine, and no further C++ capability should be needed.
Thing is, though, I don't know of any C-only compilers ;-) I thought
all of the popular ones were C/C++.
Bob
---------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org
Re: XERCES-C in C programs
Posted by Jason Jesso <jj...@global-matrix.com>.
Would this work if I compiled with a C compiler?
Thanks
Jason
Bob Jamison wrote:
> Jason Jesso wrote:
>
> >Hi:
> >
> >Can XERCES-C be used in C programs, even though it is C++? Are there C
> >bindings?
> >
> >Thanks
> >Jason
> >
> >
> >
> >---------------------------------------------------------------------
> >In case of troubles, e-mail: webmaster@xml.apache.org
> >To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
> >For additional commands, e-mail: general-help@xml.apache.org
> >
> >
> Jason,
>
> A common way to use C++ libraries is to supply your own C API
> functions in a C++ file, declare them extern "C" in the .cpp file,
> and provide a .h file which lists only the function prototypes in C
> form (no C++ includes).
>
> example:
>
> ==============
>
> myapi.cpp:
>
> #include <some_cpp_files>
> #include "myapi.h"
>
> static SomeClass *myobj;
>
> extern "C" int myapi_init(void)
> {
> myobj= new SomeClass();
> }
>
> extern "C" int another_wrapper_function(void)
> {
> myobj->someMethod();
> }
>
> ==============
>
> in myapi.h:
>
> #ifndef MYAPI_H_
> #define MYAPI_H_
>
> #ifdef __cplusplus
> extern "C" {
> #endif
> int myapi_init(void);
> int another_wrapper_function(void);
>
> #ifdef __cplusplus
> }
> #endif
>
> #endif /* MYAPI_H_*/
>
> ==============
>
> ...and in the .c files that use this:
>
> #include <myapi.h>
>
> int somefunction(void)
> {
> myapi_init(); //get an object
> another_wrapper_function();
> ...etc...
> }
>
> Basically, what you would do in the API file, is declare a
> static global object pointer, and all of the other wrapper
> functions call methods on that object.
>
> Hope this helps.
>
> Bob
>
> ---------------------------------------------------------------------
> In case of troubles, e-mail: webmaster@xml.apache.org
> To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
> For additional commands, e-mail: general-help@xml.apache.org
---------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org
Re: XERCES-C in C programs
Posted by Bob Jamison <rj...@lincom-asg.com>.
Jason Jesso wrote:
>Hi:
>
>Can XERCES-C be used in C programs, even though it is C++? Are there C
>bindings?
>
>Thanks
>Jason
>
>
>
>---------------------------------------------------------------------
>In case of troubles, e-mail: webmaster@xml.apache.org
>To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
>For additional commands, e-mail: general-help@xml.apache.org
>
>
Jason,
A common way to use C++ libraries is to supply your own C API
functions in a C++ file, declare them extern "C" in the .cpp file,
and provide a .h file which lists only the function prototypes in C
form (no C++ includes).
example:
==============
myapi.cpp:
#include <some_cpp_files>
#include "myapi.h"
static SomeClass *myobj;
extern "C" int myapi_init(void)
{
myobj= new SomeClass();
}
extern "C" int another_wrapper_function(void)
{
myobj->someMethod();
}
==============
in myapi.h:
#ifndef MYAPI_H_
#define MYAPI_H_
#ifdef __cplusplus
extern "C" {
#endif
int myapi_init(void);
int another_wrapper_function(void);
#ifdef __cplusplus
}
#endif
#endif /* MYAPI_H_*/
==============
...and in the .c files that use this:
#include <myapi.h>
int somefunction(void)
{
myapi_init(); //get an object
another_wrapper_function();
...etc...
}
Basically, what you would do in the API file, is declare a
static global object pointer, and all of the other wrapper
functions call methods on that object.
Hope this helps.
Bob
---------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org