Trouble linking static lib in CW project

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

Trouble linking static lib in CW project

3,147 Views
MK_Sirona
Contributor I
Hi Folks

I'm using CW 6.4 on WinXP and build for coldfire 5329

Ok, I got the following problem:
I have c sourcecode for an mp3 library, all gcc asm syntax.
So I built the lib in gcc and got a nice libmad.a
Disassembly looks good, all functions there. I then included the lib and the header file into my
CW c-code project. The lib-path is also in "access paths".
File Monitor shows that access to both files is okay, they are found.

However, when I try to use the library functions in my main, I get the following errors from the Linker:


Link Error   : Undefined : "mad_decoder_init"
Referenced from "decode" in main.c
Link Error   : Undefined : "mad_decoder_run"
Referenced from "decode" in main.c
Link Error   : Undefined : "mad_decoder_finish"
Referenced from "decode" in main.c

Link failed.


Those functions ARE there. In the lib and the header.

As I've been tought, path, lib and header should be enough.
I really dont know what else I should be trying. Ideas?

Any help would be much appreciated



Labels (1)
0 Kudos
9 Replies

673 Views
bkatt
Contributor IV
If your C and H files use a name like mad_decoder_init, it must appear in the assembly source with a leading underscore: _mad_decoder_init.
0 Kudos

673 Views
MK_Sirona
Contributor I
Thx for the reply, bkatt

Sources are from rockbox.org and compiled with their makefile, so I'm pretty sure the lib is fine.
Okay, what I got is the libmad.a library, and a complete header file called mad.h that takes care
of all the macros and prototypes. So, there is no name similarity here.
All function names appear without a leading underscore in the assembly, though.
Should there be one?
0 Kudos

673 Views
bkatt
Contributor IV
When writing an assembly file to work on either gnu or codewarrior, one typically defines every global with the preceding underscore for CW and without for gnu.

I have not tried what you are attempting, that is assembling a library with gnu then linking in CW. I have files that build from source on both systems, but I use the respective assemblers. My assembly files use the file type .S (capital) so that #ifdef commands will be handled by both assemblers.
0 Kudos

673 Views
CrasyCat
Specialist III
Hello
 
I would not recommend linking together object files generated by Freescale compilers with object files generated by GNU compiler.
 
Please compile and link the whole application with one single development tool chain.
 
CrasyCat
0 Kudos

673 Views
EricT
Contributor I
This could be an issue for me - I am working on a project and the goal is to generate a library that can be sold on its own.  The goal has been to compile the library in gcc since that is the more common tool among the customers who want this library, but to have it usable with both gcc and CodeWarrior since we use CW.  It sounds like this isn't possible - is that right?
0 Kudos

673 Views
J2MEJediMaster
Specialist I
In theory, if your library is written all in C and complies with the ISO C standard, you should be OK. Where you get in trouble is with assembly, where things like symbol names (as the exchange in the thread shows) can be different. Functions written in assembly might also have a special calling sequence (how arguments are passing into/out of the function) that might not match the C calling conventions used by CodeWarrior or GNU compiled in C.

Safest course of action would be to have one version of the library compiled with GNU, and the other with CodeWarrior. The customer specifies what tools they're using, and you ship them the appropriate library.

Maybe others with more experience can weigh in on the matter.

---Tom

0 Kudos

673 Views
MK_Sirona
Contributor I
Thank you for the input.

I worried that might be the case.
One last question, is it possible to use external build tools in the CW IDE?
If it was possible to tell CW to use an external linker and compiler, it could build the whole project.



Message Edited by MK@Sirona on 2008-04-14 06:51 PM
0 Kudos

673 Views
CrasyCat
Specialist III
Hello
 
There is no easy way of doing that. You need a make utility and then you need to write a make file to build the application.
 
You can use GNU make utility without any problem.
 
Once you are there you have 2 solutions:
  1- Build from batch (DOS command window) and use the IDE only for debugging.
      Look for FAQ-27444 on www.freescale.com for information on how to achieve that.
 
  2- Build and debug from the IDE.
     You can create a project using the "External Build Wizard".
     You can specify the command used to build the application through the Make utility 
     when you create the project.
 
But in both cases you need to create a make file first and look for a make utility. 
 
I hope this helps.
 
CrasyCat
0 Kudos

673 Views
MK_Sirona
Contributor I
That's good news.
Got gnu make and  CW can export a project to a gnu makefile, so I can work from there.
That will save a lot of work.

Thanks again for the quick help

Greetz - Matt


0 Kudos