unresolved external

Discussion in 'C++' started by Mark, Dec 12, 2005.

  1. Mark

    Mark Guest

    I'm trying to write an RAS class on windows ad RasDial's callback
    function requires it to either not be a class member or for it to be
    static. I went for the static option so in the header file I declared an
    extern variable for the class outside of the class definition so I
    could use it in the static function, like so:

    #ifndef RasClientH
    #define RasClientH

    #include <ras.h>
    #include <raserror.h>

    class RasClient
    {
    [snip]
    };

    extern RasClient ras;

    #endif

    then in the header file for the class I will be using ras in I put:

    #ifndef MainFormH
    #define MainFormH

    #include "RasClient.h"

    [snip]

    class TfrmMain : public TForm
    {
    [snip]
    private: // User declarations
    RasClient ras;
    [snip]
    };

    #endif

    but when it's linking I'm getting an error saying '[Linker Error]
    Unresolved external '_ras' referenced from RASCLIENT.OBJ'. Can anyone
    tell me what I'm doing wrong?

    TIA
    Mark, Dec 12, 2005
    #1
    1. Advertising

  2. Mark wrote:

    > I'm trying to write an RAS class on windows ad RasDial's callback
    > function requires it to either not be a class member or for it to be
    > static. I went for the static option so in the header file I declared an
    > extern variable for the class outside of the class definition so I
    > could use it in the static function, like so:
    >
    > #ifndef RasClientH
    > #define RasClientH
    >
    > #include <ras.h>
    > #include <raserror.h>
    >
    > class RasClient
    > {
    > [snip]
    > };
    >
    > extern RasClient ras;
    >

    This extern declaration tells the compiler that a global object
    with name ras exists. It does not define (instantiate) it.
    You do not instantiate it anywhere in the code you showed.
    Just add

    RasClient ras;

    in one of your implementation files. That should solve your linker
    problem, but I'm not sure it's really what you want to do.

    Stephan
    Stephan Hoffmann, Dec 12, 2005
    #2
    1. Advertising

  3. Mark

    Mark Guest

    Stephan Hoffmann wrote:
    > This extern declaration tells the compiler that a global object
    > with name ras exists. It does not define (instantiate) it.
    > You do not instantiate it anywhere in the code you showed.

    [snip]

    So declare it outside of a class definition?

    Mark
    Mark, Dec 12, 2005
    #3
  4. Mark

    Peter_Julian Guest

    "Mark" <> wrote in message
    news:439ce638$...
    | Stephan Hoffmann wrote:
    | > This extern declaration tells the compiler that a global object
    | > with name ras exists. It does not define (instantiate) it.
    | > You do not instantiate it anywhere in the code you showed.
    | [snip]
    |
    | So declare it outside of a class definition?
    |
    | Mark

    No, define it outside the class definition.
    Peter_Julian, Dec 12, 2005
    #4
    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. John Harrison
    Replies:
    0
    Views:
    1,044
    John Harrison
    Jul 20, 2003
  2. Izak Pretorius
    Replies:
    2
    Views:
    1,567
    Christopher
    Sep 14, 2003
  3. Rodolphe
    Replies:
    4
    Views:
    1,060
    Rodolphe
    Oct 3, 2003
  4. mp
    Replies:
    2
    Views:
    6,895
  5. Scott Allen
    Replies:
    8
    Views:
    10,907
    Scott Allen
    May 2, 2004
Loading...

Share This Page