This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Link error on missing symbol that is there.

The symbol X shows up in the link map, but the linker still generates unresolved symbol errors for X in main. Any ideas?

File Main.c:

extern xdata X[];
static char xdata* p = X;

void main( void )
{
}

File Sub.c:

char xdata X[] _at_ 0x0012;

static char xdata* p = X;

  • Since no array size is given in Sub.c the compiler doesn't provide space and may even assume that X is external (therefore it is never created). This should work without 'data different' warnings;

    File Main.c:

    extern char xdata X;
    static char xdata* p = X;
    
    void main( void )
    {
    }


    File Sub.c:
    char xdata X _at_ 0x0012;
    
    static char xdata* p = X;

    The other thing you can do is specify the array dimensions when declaring it.
    Best Luck

  • You haven't declared a type for X in the extern in Main.c, so 'C' will assume int, but in the definition in Sub.c you've specified char.

    I would expect to get some sort of complaint from the Linker about this, though perhaps not "unresolved!"

  • Thanks for spotting the error. However it still does not link.

    File Main.c:
    
    extern char xdata X[];
    static char xdata* p = X;
    
    void main( void )
    {
    }
    

    File Sub.c:
    
    char xdata X[] _at_ 0x0012;
    
    static char xdata* p = X;
    

  • You still need a dimension when creating the actual array. Otherwise the compiler doesn't actually assign space to the variable. (In the '167 compiler it produces a warning that the variable is assumed to be external.

    File Sub.c:
    
    char xdata X[5] _at_ 0x0012;
    
    static char xdata* p = X;

    or

    File Sub.c:
    
    char xdata X _at_ 0x0012;
    
    static char xdata* p = &X;


  • "You still need a dimension when creating the actual array"

    Now you mention it, I seem to remember that this came up a while ago; or it might've been someone declaring an array with dimension zero:

    char xdata X[0] _at_ 0x0012;