"undefined symbol" right after execution of program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mahmoodn
    New Member
    • May 2009
    • 77

    "undefined symbol" right after execution of program

    Hi
    I have a data type and I can instantiate a variable of that type. like this:

    Code:
    FetchAddr faddr(VirtualMemoryAddress( 0x0a ));
    The definition of FetchAdr is:
    Code:
    struct FetchAddr {
      Flexus::SharedTypes::VirtualMemoryAddress theAddress;
      FetchAddr(Flexus::SharedTypes::VirtualMemoryAddress anAddress)
         : theAddress(anAddress)
      { }
    };
    Now I have a class that faddr is a private (or public) variable

    Code:
    class FLEXUS_COMPONENT(BPred)  {
      static FetchAddr faddr;
    
      public:
       FLEXUS_COMPONENT_CONSTRUCTOR(BPred)
        : base( FLEXUS_PASS_CONSTRUCTOR_ARGS )
        {
           faddr = VirtualMemoryAddress( 0x0a );
        }
    	...
    }
    Assume the macros are defined properly.

    The code compiles and links without any problem. However when I start the program, it says:
    "undefined symbol: _ZN6nBPred14BPr edComponent8fad dr"

    it says there no symbol for faddr.

    any idea about that?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    faddr is a class static variable. That says faddr can be accessed without a FLEXUS_COMPONEN T object. However this does not create faddr.

    You need to declare a static object faddr outside any class to create the object you want to access from inside the class.

    Comment

    • mahmoodn
      New Member
      • May 2009
      • 77

      #3
      Is there any way to avoid static variable? any alternative?

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        This situation is usually handled by creating a Singleton object.

        Read this: http://bytes.com/topic/c/insights/65...erns-singleton

        It's in the C++ Insights forum.

        Comment

        Working...