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

Discussion in 'C++' started by sachinv1821@gmail.com, Jan 7, 2008.

  1. Guest

    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 :)
    , Jan 7, 2008
    #1
    1. Advertising

  2. ciccio Guest

    ciccio, Jan 7, 2008
    #2
    1. Advertising

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

    On Jan 7, 11:17 am, "" <>
    wrote:
    > 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++.
    tragomaskhalos, Jan 7, 2008
    #3
  4. Guest

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

    On Jan 7, 4:32 pm, tragomaskhalos <>
    wrote:
    > On Jan 7, 11:17 am, "" <>
    > wrote:
    >
    > > 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++.


    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!!
    , Jan 7, 2008
    #4
  5. Re: How To Accessing C++ Class objects in C : getting error fatal

    On Jan 7, 11:41 am, "" <>
    wrote:
    >
    > 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?
    tragomaskhalos, Jan 7, 2008
    #5
  6. Guest

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

    On Jan 7, 4:49 pm, tragomaskhalos <>
    wrote:
    > On Jan 7, 11:41 am, "" <>
    > wrote:
    >
    >
    >
    > > 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?


    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.......
    , Jan 7, 2008
    #6
  7. Re: How To Accessing C++ Class objects in C : getting error fatal

    On Jan 7, 11:54 am, "" <>
    wrote:
    > On Jan 7, 4:49 pm, tragomaskhalos <>
    > wrote:
    >
    > > On Jan 7, 11:41 am, "" <>
    > > wrote:

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

    >
    > 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.
    tragomaskhalos, Jan 7, 2008
    #7
  8. Guest

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

    On Jan 7, 5:14 pm, tragomaskhalos <>
    wrote:
    > On Jan 7, 11:54 am, "" <>
    > wrote:
    >
    >
    >
    >
    >
    > > On Jan 7, 4:49 pm, tragomaskhalos <>
    > > wrote:

    >
    > > > On Jan 7, 11:41 am, "" <>
    > > > wrote:

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

    >
    > > 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 :)
    , Jan 7, 2008
    #8
  9. Re: How To Accessing C++ Class objects in C : getting error fatal

    On Jan 7, 1:54 pm, "" <>
    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.......


    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 :)
    Ioannis Gyftos, Jan 7, 2008
    #9
  10. James Kanze Guest

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

    On Jan 7, 12:17 pm, "" <>
    wrote:

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

    --
    James Kanze (GABI Software) mailto:
    Conseils en informatique orient�e objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34
    James Kanze, Jan 7, 2008
    #10
  11. Guest

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

    On Jan 7, 5:14 pm, tragomaskhalos <>
    wrote:
    > On Jan 7, 11:54 am, "" <>
    > wrote:
    >
    >
    >
    > > On Jan 7, 4:49 pm, tragomaskhalos <>
    > > wrote:

    >
    > > > On Jan 7, 11:41 am, "" <>
    > > > wrote:

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

    >
    > > 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
    , Jan 8, 2008
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Polo Lee
    Replies:
    0
    Views:
    2,709
    Polo Lee
    Jul 7, 2003
  2. Kevin Flood
    Replies:
    0
    Views:
    1,002
    Kevin Flood
    Sep 8, 2004
  3. 7stud
    Replies:
    11
    Views:
    661
    Dennis Lee Bieber
    Mar 20, 2007
  4. Replies:
    3
    Views:
    334
    SM Ryan
    Jan 7, 2008
  5. Replies:
    2
    Views:
    106
Loading...

Share This Page