linker error I can't seem to solve - " Undefined symbol OS_CPU_SR_Save() (referred from app.c.c.LPC1768.o)." in file "/"

04 Feb 2012

I'm trying to port uC-OS-II to use on the mbed LCP1768 and I've solved many of the problems but I can't seem to get over these errors.

  • Undefined symbol OS_CPU_SR_Save() (referred from app.c.c.LPC1768.o)." in file "/"
  • Undefined symbol OS_CPU_SR_Restore(unsigned) (referred from app.c.c.LPC1768.o)." in file "/"

There are methods that call the first two functions from the main program file (app.c). The methods are declared as (in a .h file):

#define  OS_ENTER_CRITICAL()  { cpu_sr = OS_CPU_SR_Save(); }  
#define  OS_EXIT_CRITICAL()   { OS_CPU_SR_Restore(cpu_sr); }

OS_CPU_SR  OS_CPU_SR_Save(void);
void       OS_CPU_SR_Restore(OS_CPU_SR cpu_sr);

These functions are assembly functions in a .s file:

OS_CPU_SR_Save
    MRS     R0, PRIMASK                                         ; Set prio int mask to mask all (except faults)
    CPSID   I
    BX      LR

OS_CPU_SR_Restore
    MSR     PRIMASK, R0
    BX      LR

I'm not sure what could cause these sort of errors, please help. In my main (app.c) file I #include the .h so that shouldn't be the problem. There are other .c files that use these functions and if I comment out the declarations those files don't compile.

04 Feb 2012

I found the solution by reading http://www.uit.edu.vn/data/gtrinh/TH012/tlthamkhao/cpp-ti/15688.html

I needed to replace:

OS_CPU_SR  OS_CPU_SR_Save(void);
void       OS_CPU_SR_Restore(OS_CPU_SR cpu_sr);

with:

extern "C" OS_CPU_SR  OS_CPU_SR_Save(void);
extern "C" void       OS_CPU_SR_Restore(OS_CPU_SR cpu_sr);