How To Accessing C++ Class objects in C : getting error fatal error

S

sachinv1821

hi ,
i am Getting this Error
fatal error C1189: #error : "eh.h is only for C++!"
my Problem is i am Having C++ librabry and Appropriate .h file
i want to Access Them is .c File Files.....
to Be More Specific i am Creating a C++ Object in a C file...
this Giving me the error!!! :(

can Any Body Please Help me


How to Access the C++ object in C file...
Thanks In Advance :)
 
T

tragomaskhalos

hi ,
i am Getting this Error
fatal error C1189: #error : "eh.h is only for C++!"
my Problem is i am Having C++ librabry and Appropriate .h file
i want to Access Them is .c File Files.....
to Be More Specific i am Creating a C++ Object in a C file...
this Giving me the error!!! :(

can Any Body Please Help me

How to Access the C++ object in C file...
Thanks In Advance :)

In general, you can't.
You can provide a procedural interface instead,
and declare it in a header file like this:

#ifdef __cplusplus
extern "C" {
#endif
void some_function(int, char*, double); // or whatever
#ifdef __cplusplus
}
#endif

This can then be included from both C and C++.
 
S

sachinv1821

In general, you can't.
You can provide a procedural interface instead,
and declare it in a header file like this:

#ifdef __cplusplus
extern "C" {
#endif
void some_function(int, char*, double); // or whatever
#ifdef __cplusplus}

#endif

This can then be included from both C and C++.

Ya i can Do that But There are Many Class and there are many
Functions....so Writting the Wrapper For Each is Not Possible..
so is there any Alternative method or any Buit-in COde Genarator S/w
that can Do this Task!!
Thanks For the Reply :)! waiting ahead For Reply!!
 
T

tragomaskhalos

Ya i can Do that But There are Many Class and there are many
Functions....so Writting the Wrapper For Each is Not Possible..
so is there any Alternative method or any Buit-in COde Genarator S/w
that can Do this Task!!
Thanks For the Reply :)! waiting ahead For Reply!!- Hide quoted text -

If this is the case why on earth are you trying to do this from C?
Rename your .c files to .cpp and compile them as C++, why don't you?
 
S

sachinv1821

If this is the case why on earth are you trying to do this from C?
Rename your .c files to .cpp and compile them as C++, why don't you?

Thanks For Reply i MIght have Done that Problem i am Doing Something
in PreDefined Frame-Work Which is Written in C and i got a Third Party
Library which is in C++ ,i am Not Getting HOw to Hormonize these
two ... [:( ]
since i cannt Change the Framework as well i cannt do anythig in Third
Party Lib.......
 
T

tragomaskhalos

On Jan 7, 11:41 am, "(e-mail address removed)" <[email protected]>
wrote:
If this is the case why on earth are you trying to do this from C?
Rename your .c files to .cpp and compile them as C++, why don't you?

Thanks For Reply i MIght have Done that Problem i am Doing Something
in PreDefined Frame-Work Which is Written in C and i got a Third Party
Library which is in C++ ,i am Not Getting HOw to Hormonize these
two ... [:( ]
since i cannt Change the Framework as well i cannt do anythig in Third
Party Lib.......

In that case you will have to isolate the code that accesses the 3rd
party library into a C++ module and provide a procedural interface
to that module that's callable from C using the technique I described
before.
 
S

sachin.vastrad

On Jan 7, 4:49 pm, tragomaskhalos <[email protected]>
wrote:
Thanks For Reply i MIght have Done that Problem i am Doing Something
in PreDefined Frame-Work Which is Written in C and i got a Third Party
Library which is in C++ ,i am Not Getting HOw to Hormonize these
two ... [:( ]
since i cannt Change the Framework as well i cannt do anythig in Third
Party Lib.......

In that case you will have to isolate the code that accesses the 3rd
party library into a C++ module and provide a procedural interface
to that module that's callable from C using the technique I described
before.- Hide quoted text -

- Show quoted text -

ya I think this ll be Better Option For ME
Thank you :)
 
I

Ioannis Gyftos

Thanks For Reply i MIght have Done that Problem i am Doing Something
in PreDefined Frame-Work Which is Written in C and i got a Third Party
Library which is in C++ ,i am Not Getting HOw to Hormonize these
two ... [:( ]
since i cannt Change the Framework as well i cannt do anythig in Third
Party Lib.......

I don't think I'm such a weirdo, but this seriously hurts my eyes.
Please post in standard English, which is also a quite an efficient
way to get you more helpful responses :)
 
J

James Kanze

i am Getting this Error
fatal error C1189: #error : "eh.h is only for C++!"

I'm not familiar with the compiler you are using (or maybe I
am---I don't know what compiler you are using), but the text of
the error message seems very, very clear. The author of this
file, for whatever reasons, did *not* want his header processed
by a C compiler. Which probably means that you'll have to
either give up using the library, or wrap it in an additional C
layer which can be called from C++.

Note that the error message says "#error". That sounds like the
compiler has encountered an #error preprocessor directive.
Perhaps something like:

#ifndef __cplusplus
#error eh.h is only for C++
#endif

You could always try to invoke the C compiler with something
like -D__cplusplus or /D__cplusplus, but this is undefined
behavior, and of course, if the original author didn't want the
file compiled with a C compiler, there is probably a reason.
my Problem is i am Having C++ librabry and Appropriate .h file
i want to Access Them is .c File Files.....

You can't.
to Be More Specific i am Creating a C++ Object in a C file...
this Giving me the error!!! :(

You can't.
can Any Body Please Help me
How to Access the C++ object in C file...

If you compile with C, there is no way that you're be able to
instantiate a C++ class that is not a POD. If you compile with
C, there's no way you can do anything not allowed in C. (Also,
if you compile with C, this forum really isn't the appropriate
place to post your question. comp.lang.c would be more
appropriate, but I can just imagine the response you'll get
there.)
 
S

sachinv1821

On Jan 7, 4:49 pm, tragomaskhalos <[email protected]>
wrote:
Thanks For Reply i MIght have Done that Problem i am Doing Something
in PreDefined Frame-Work Which is Written in C and i got a Third Party
Library which is in C++ ,i am Not Getting HOw to Hormonize these
two ... [:( ]
since i cannt Change the Framework as well i cannt do anythig in Third
Party Lib.......

In that case you will have to isolate the code that accesses the 3rd
party library into a C++ module and provide a procedural interface
to that module that's callable from C using the technique I described
before.

hello there i got this Problem Solved (i written a wrapper above the c+
+ lib)
now its Compling and linking correctly! But again i encountered new
problem
Actually i made this C project as a ACM driver / Dll File now when i
try to load the DLL/ACM its not not loding flaging the error no
998(invalid access of Memory...)
if any one know please help me
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top