This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/EK-TM4C1294XL: Linking external functions and variables?

Part Number: EK-TM4C1294XL

Tool/software: Code Composer Studio

In my application I have the main.c file, and the I have a file, Codes.c.

Codes.c contains a lot of bit patterns and then:

static volatile char tempcode [16384];
static volatile int CodeLength;
static volatile int CodeIdx;

void BuildCode(int CL) {

int i;

  CodeLength=CL;

  tempcode[..]= bla.bla;
  ..
  ..
}

In main.c I have the following:

//Links to Codes.c
extern void BuildCode(int CL);
extern char tempcode [16384];
extern int CodeLength, CodeIdx;


..
..

void CGsetupISR(void)
{
    unsigned short NextData;
    //Clr interrupt
    GPIOIntClear(GPIO_PORTQ_BASE, GPIO_PIN_2);

    //Clr DC
    GPIOPinWrite(GPIO_PORTQ_BASE,GPIO_PIN_0, 0);

    if (CodeLoad==1)
    {
        CodeIdx++;
        if (CodeIdx>CodeLength)
        {
            CodeLoad=2;
            return;
        }
    }
    else
    {
      ..
      ..
    }

    if (CodeLoad=1)
        NextData=tempcode[CodeIdx];
    else
        ..

}

void UploadCode(int len) {
    BuildCode(len);  //Load code into buffer and copy 7 times

    CodeLoad=1;
    CodeIdx=0;

    SendFirstCGData();

}


This all compiles fine, but entering the link phase, I get:
 undefined       first referenced
  symbol             in file     
 ---------       ----------------
 CodeIdx         ./main.obj      
 CodeLength      ./main.obj      
 tempcode        ./main.obj      

I have tried:

#include "Codes.c"

.. but then I get:

error #10056: symbol "BuildCode" redefined: first defined in "./Codes.obj"; redefined in "./main.obj"

This comes with or without commenting out the external ref. to that function.

How do I solve this?

PS. I have tried to edit typos, obvious wrong format in the code parts etc, but this editor really do not want you to edit anything?

  • Static variables ..

    Ja Hv said:
    static volatile char tempcode [16384];
    static volatile int CodeLength;
    static volatile int CodeIdx;

    ... are available only within the scope in which they are defined.  In this particular case, they are available only within the file Codes.c.  To make them global across the program, remove the static keyword.

    Writing lines like these in main.c ...

    Ja Hv said:
    //Links to Codes.c
    extern void BuildCode(int CL);
    extern char tempcode [16384];
    extern int CodeLength, CodeIdx;

    ... is not typically how it is done.  Please use the method described in this FAQ (not from TI).

    Thanks and regards,

    -George