Using libraries in CW6.2 for Coldfire

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

Using libraries in CW6.2 for Coldfire

1,202 Views
brian_kbs
Contributor II

Hi all,

I'm using CodeWarrior 6.2 with the MCF51QE128.

 

In my application, I want to use some functions from an existing C source library. I've managed to compile the library (first time for me), and call the specific functions I need from my application. When I compile the application, it works OK, but the entire library seems to end up inside my processor. This wastes a huge amount of flash space that I will need to use for other code later.

 

Question: 

Does anyone know how to get CodeWarrior to remove the unused parts of the library? (I thought this would happen automatically if I created a library, that's why I did it that way...)

 

What I did: 

I created two projects: one to compile the library and the other for my application. 

 

To compile the library, I imported all the source files into the project. Then I went to

"Targets" panel -> Standard -> Coldfire Target

and changed the Project Type to "Library", and gave it a name like mylib.lib

At this stage I hit the "Make" button. It all compiled OK and the .lib appeared. Good!

 

Then I created a separate project for the application. I wrote a "main" routine to call the functions I need. Then I went to the "Libs" section of the "Files" tab and added the .lib file.

 

When I "make" the application project and download it into the processor, it tells me it is transferring 117kB. This is roughly the amount of code in the full library. Am I doing something wrong? I really hope I don't have to restructure or rewrite parts of the library by hand!

 

Thanks,

Brian 

Labels (1)
0 Kudos
4 Replies

385 Views
CrasyCat
Specialist III

Hello

 

Make sure you did not check the "Disable Deadstripping" check box in the project's Coldfire linker panel.

 

CrasyCat

0 Kudos

385 Views
brian_kbs
Contributor II

Hi CrasyCat,

Thanks for the suggestion. That box was unchecked.

 

I actually tried checking it to see what happens, and I got several messages such as

Link Error : Undefined "sqrt"

These errors must come from dead functions that were previously getting stripped out? 

 

So the "deadstripping" doesn't seem to be the issue. Any other options I can check?

 

I'd like to recheck my estimate of how much space I should really need. I'd welcome any suggestions on how best to do this! If I look at the "Code" column in the Files panel, does it give me the amount of code actually used from that file, or the total of all functions within the file?

 

Brian 

0 Kudos

385 Views
CrasyCat
Specialist III

Hello

 

Be careful the size indicated in the .mcp window indicates the worst case size (i.e. The size of the application before dead striping).

 

If you want to see your real application size, please look at the .xMAP file generated after linking.

Toward the end of the file you will see the real size of the code (sections .text and .code), variable (sections .data and .bss).

 

 

CrasyCat

0 Kudos

385 Views
brian_kbs
Contributor II

Hi CrasyCat,

Thanks for your tips. It's a while since I last posted, so in the unlikely event that anyone is in suspense over this, I thought I'd post the conclusion.

 

It turned out that the problem is with the code itself. We got the library from an open source project that was intended for computers rather than embedded processors, so it is a bit inefficient in terms of space. There was a massive amount of code getting called from error conditions that I know will never get executed. But the compiler/linker doesn't understand that, so my code ended up 2 or 3 times the size it should be.

 

So basically we are rewriting our own version of this library now. Thanks for helping me to understand what was going on!

 

Brian 

0 Kudos