Link error L1818 when transplanting uc/OS-II to MC9S12C32

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Link error L1818 when transplanting uc/OS-II to MC9S12C32

Jump to solution
4,699 Views
WayneYoung
Contributor I

I am trying to transplant uC/OS-II to MC9S12C32 with CodeWarrior Development Studio for HCS12(X) Microcontrollers v4.7.1 , after compiling all the codes, I clicked the "make" button and got 51 link error L1818.

Here is an example:

link error: L1818 :smileyfrustrated:ymbol 20 - OSCtxSwCtr duplicated in uCOS_II.C.o and OS_CORE.C.o

 

uCOS_II.C:

#define  OS_GLOBALS                           #include "includes.h"#define  OS_MASTER_FILE                      #include "os_core.c"//#include "os_flag.c"//#include "os_mbox.c"//#include "os_mem.c"//#include "os_mutex.c"//#include "os_q.c"#include "os_sem.c"#include "os_task.c"#include "os_time.c"   

 

And OSCtxSwCtr is defined in uCOS_ii.h:

OS_EXT  INT32U            OSCtxSwCtr;  

 

includes.h:

 

#include    <stdio.h>#include    <string.h>#include    <ctype.h>#include    <stdlib.h>//#include    <conio.h>//#include    <dos.h>#include    <setjmp.h>#include    "os_cpu.h"#include    "os_cfg.h"//#include    "\software\blocks\pc\bc45\pc.h"#include    "ucos_ii.h"

 

 

OSCtxSwCtr appears in OS_CORE.C at three places, and all of them are used as Variables. So I do not know what is wrong.

 

Anyone would help to tell me how to do next?

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
2,146 Views
CompilerGuru
NXP Employee
NXP Employee

As uCOS_II.C includes the source code of os_core.c,

os_core.c should not be compiled as part of the project as well.

According to the error message this did happen though as the linker lists both object files.

The simplest fix is to remove os_core.c from the project. Alternatively if the project has multiple build targets then os_core.c could also be added just to a secondary build target whose output does not get linked in.

 

Daniel

View solution in original post

0 Kudos
Reply
5 Replies
2,146 Views
WayneYoung
Contributor I

Thank you all!

I misunderstood your meanning at first, but when I had a try, I realised this. Thank you very much.

0 Kudos
Reply
2,147 Views
CompilerGuru
NXP Employee
NXP Employee

As uCOS_II.C includes the source code of os_core.c,

os_core.c should not be compiled as part of the project as well.

According to the error message this did happen though as the linker lists both object files.

The simplest fix is to remove os_core.c from the project. Alternatively if the project has multiple build targets then os_core.c could also be added just to a secondary build target whose output does not get linked in.

 

Daniel

0 Kudos
Reply
2,146 Views
WayneYoung
Contributor I

Remove the OS_CORE.C... You mean remove it from uCOS_ii.h or remove it from the whole project?

OS_CORE.C is an important and neccessary part in RTOS uc/os-ii. If I removed it, the project would not work at all.

Never the less, the files listed below os_core.c had the same problem as above. It would impossible for me to remove all of them.

0 Kudos
Reply
2,146 Views
CompilerGuru
NXP Employee
NXP Employee

>You mean remove it from uCOS_ii.h or remove it from the whole project?

 

I said that the "simplest fix is to remove os_core.c from the project", so I was suggesting the second.

Maybe the first one would work just as well.

 

Anyway the problem is that the source code inside of  os_core.c is compiled multiple times, once as its own source file by listing os_core as file in the project and at least once as being included in uCOS_ii.h.

The result is the link error L1818, so you have to adapt the project so that it only compiles this file (and probably any other *.c file) just once.

It's not common practice to include *.c files into other *.c files, but it is legal and should work as long as you do not compile the included c source file as well (not compiling it is done by not adding it to the CW project....).

 

> OS_CORE.C is an important and necessary part in RTOS uc/os-ii.

You need to compile it once, that's often enough even for important files :smileywink:.

 

>Never the less, the files listed below os_core.c had the same problem as above.

> It would impossible for me to remove all of them.

Same story for all c files.

 

I don't know this os, but to me it looks like you either should compile uCOS_II.C or compile all the source file this one includes, but not both. Check the documentation, or if it ships with sample projects check what is compiled in those.

 

Daniel

0 Kudos
Reply
2,146 Views
CrasyCat
Specialist III

Hello

 

Apparently the function OSCtxSwCtr is implemented in both  uCOS_II.C.o and OS_CORE.C.o.

You need either to remove uCOS_II.c or OS_CORE.c from your project.

 

If you need both C source file remove the function OSCtxSwCtr from one of the module.

 

If the function OSCtxSwCtr is implemented in a .h file, define it as static.

 

CrasyCat

0 Kudos
Reply