Is a struct preserved when used into a cpp file?

Discussion in 'C++' started by CViniciusM, Jan 27, 2004.

  1. CViniciusM

    CViniciusM Guest

    Hello,

    a) I have a .h (header file) that declares a struct:
    ....
    typedef struct {
    UINT4 state[4]; /* state (ABCD) */
    UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
    unsigned char buffer[64]; /* input buffer */
    } MD5_CTX;
    ....

    b) and I have .c (C source file) that uses the header above:
    ....
    void MD5Init(MD5_CTX *context);
    ....

    c) I have created a .lib (library file) with the functions above.

    I have used the header file above into a .cpp (C++ source file). The
    ..cpp file uses the .lib functions, but the compiles says "Unresolved
    external MD5Init(MD5_CTX*) ...".

    I think the .lib was included correctly on the project, so is a struct
    preserved when used into a cpp file?

    Thanks in advance, Vinicius.

    PS: I'm using actually the Borland C++Builder 3 IDE for this project,
    but my doubts is concerned about the theory, excuse me for anything.
     
    CViniciusM, Jan 27, 2004
    #1
    1. Advertising

  2. CViniciusM wrote:
    >
    > Hello,
    >
    > a) I have a .h (header file) that declares a struct:
    > ...
    > typedef struct {
    > UINT4 state[4]; /* state (ABCD) */
    > UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
    > unsigned char buffer[64]; /* input buffer */
    > } MD5_CTX;
    > ...
    >
    > b) and I have .c (C source file) that uses the header above:
    > ...
    > void MD5Init(MD5_CTX *context);
    > ...
    >
    > c) I have created a .lib (library file) with the functions above.
    >
    > I have used the header file above into a .cpp (C++ source file). The
    > .cpp file uses the .lib functions, but the compiles says "Unresolved
    > external MD5Init(MD5_CTX*) ...".


    In the header file you have a prototype for the function.
    What does it look like?

    On epossibility would eg. be:

    extern "C" void MD5Init( MD5_CTX *constext );

    you need to tell the C++ compiler, that MD5Init was compiled with
    a C compiler, such that the C++ compiler doesn't use name mangling
    for that function.

    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Jan 27, 2004
    #2
    1. Advertising

  3. CViniciusM

    CViniciusM Guest

    Karl Heinz Buchegger <> wrote in message news:<>...
    > CViniciusM wrote:
    > >
    > > Hello,
    > >
    > > a) I have a .h (header file) that declares a struct:
    > > ...
    > > typedef struct {
    > > UINT4 state[4]; /* state (ABCD) */
    > > UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
    > > unsigned char buffer[64]; /* input buffer */
    > > } MD5_CTX;
    > > ...
    > >
    > > b) and I have .c (C source file) that uses the header above:
    > > ...
    > > void MD5Init(MD5_CTX *context);
    > > ...
    > >
    > > c) I have created a .lib (library file) with the functions above.
    > >
    > > I have used the header file above into a .cpp (C++ source file). The
    > > .cpp file uses the .lib functions, but the compiles says "Unresolved
    > > external MD5Init(MD5_CTX*) ...".

    >
    > In the header file you have a prototype for the function.
    > What does it look like?
    >
    > On epossibility would eg. be:
    >
    > extern "C" void MD5Init( MD5_CTX *constext );
    >
    > you need to tell the C++ compiler, that MD5Init was compiled with
    > a C compiler, such that the C++ compiler doesn't use name mangling
    > for that function.


    Yes, I did do the following:
    md5.h:
    #ifdef __cplusplus
    ....
    extern "C" void MD5Init(MD5_CTX *context);
    ....
    #else
    ....
    void MD5Init(MD5_CTX *context);
    ....
    #endif

    This way, I can use this header file both to compile a C library as to
    use on a C++ project (including the header file into a C++ source file
    and the library into the project).

    Thank you.
     
    CViniciusM, Jan 27, 2004
    #3
    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. DrUg13
    Replies:
    1
    Views:
    477
    DrUg13
    Feb 10, 2004
  2. Alex Vinokur
    Replies:
    7
    Views:
    410
    Greg Comeau
    Nov 15, 2004
  3. Vinu
    Replies:
    9
    Views:
    623
  4. Chris Fogelklou
    Replies:
    36
    Views:
    1,391
    Chris Fogelklou
    Apr 20, 2004
  5. www.hitechskill.com
    Replies:
    0
    Views:
    1,355
    www.hitechskill.com
    Apr 9, 2006
Loading...

Share This Page