Linking Codewarrrior Libraries using command line

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

Linking Codewarrrior Libraries using command line

5,746 Views
CW_user
Contributor I

Hi,

I was trying to link pre built runtime libraries using command line,but the libraries have calls to functions defined in other init files,Is there a neat way of linking them recursively?


$(SYSTEM).elf: $(OBJ_FILES)
        @echo ==== Creating $(SYSTEM).out from obj files ====
 $(LINK_TOOL)  $@ $(LINK_TOOL_OPTS) $(LFLAGS)

The LFLAGS has names of the libraries.Could you anyone suggest a way to link the libraries which have calls to functions listed in the $(OBJ_FILES)?I have trie dto use $^ -o  option but my make cannot see it as a valid command.

Thanks

Labels (1)
0 Kudos
Reply
10 Replies

2,710 Views
CW_user
Contributor I
No,my make does not recognize any automatic variables tried using $+ also.Any other way to build it without using the automatic variables?
0 Kudos
Reply

2,710 Views
RichTestardi
Senior Contributor II

You can always explicitly list the prerequisites rather than use automatic variables, but it makes the Makefiles very hard to maintain.

 

What make are you using?  And on what platform are you running?  It sure seems like your Makefile might have been written for gnu make.  Can you just install gnu make?

 

Your alternative is just to use a make-less script to build your project using the command-line tools -- if the project is small, it won't be that painful to rebuild everything every time.

0 Kudos
Reply

2,710 Views
CW_user
Contributor I

I see that you had similar issues in this thread Re: CW7.1-CF: Command-line vs. GUI operation .I gues smy issue is also with ordering.

 

OBJ_FILES is nothing but my C objects.Here are my make lines.

TOOL_LIB=\

$(TOOL_ROOT)/PowerPC_EABI_Support/Runtime/Lib/Runtime.PPCEABI.E.a \

$(TOOL_ROOT)/PowerPC_EABI_Support/MSL/MSL_C/PPC_EABI/Lib/MSL_C.PPCEABI.bare.E.a

LFLAGS = $(TOOL_LIB) -Map $(SYSTEM).map

C_OBJECTS = $(C_FILES:.c=.o)

S_OBJECTS = $(S_FILES:.s=.o)

OBJ_FILES = $(C_OBJECTS) $(S_OBJECTS)

 

$(SYSTEM).elf: $(OBJ_FILES)

@echo ==== Creating $(SYSTEM).out from obj files ====

$(LINK_TOOL)$^ -o $@ $(LINK_TOOL_OPTS) $(LFLAGS)

 

$(C_OBJECTS) : $(C_FILES)

@echo Building file $@...

$(COMPILE_TOOL) $(COMPILE_TOOL_OPTS) $(CFLAGS) -o $@ -c $(@:.o=.c)

$(S_OBJECTS) : $(S_FILES)

@echo Building assembly file $@...

$(ASSEMBLY_TOOL) $(ASSEMBLY_TOOL_OPTS) $(AFLAGS) -o $@ -c $(@:.o=.s)

 

This make worked previously where I use $^  to include all prerequites without ordering.But my current make doesn't recognize that automatic variable.So if I now do not use that,then when linking my library I guess it cannot use the object for __ppc_eabi_init.c on which the library is dependent on.

    Any suggestions how I can work around this issue?

Thanks!

0 Kudos
Reply

2,710 Views
RichTestardi
Senior Contributor II

You say you used to use this:

 

$(LINK_TOOL)$^ -o $@ $(LINK_TOOL_OPTS) $(LFLAGS)

 

But that $^ does not work with your current make.

 

Does $+ work in place of $^?  Note that the "-o" goes with the $@ -- I had totally missed that they were separated above.

 

The differences between those automatic variables are listed below.

 

$^ The names of all the prerequisites, with spaces between them. For prerequisites which are archive members, only the member named is used (see Archives). A target has only one prerequisite on each other file it depends on, no matter how many times each file is listed as a prerequisite. So if you list a prerequisite more than once for a target, the value of $^ contains just one copy of the name. This list does not contain any of the order-only prerequisites; for those see the `$|' variable, below.
$+ This is like `$^', but prerequisites listed more than once are duplicated in the order they were listed in the makefile. This is primarily useful for use in linking commands where it is meaningful to repeat library file names in a particular order.

$| The names of all the order-only prerequisites, with spaces between them.
Message Edited by Rich T on 2009-04-01 08:24 AM
0 Kudos
Reply

2,710 Views
CW_user
Contributor I

Actually I do include __ppc_eabi_init.c in my make.It should build it before linking all the objetcs.For some reason ,when linking with the runtime library that is calling the functions,it is not able to use it as prerequiste in my make .I do not get this when building uing the IDE.

Here is how I build my objects and link them


$(SYSTEM).elf: $(OBJ_FILES)
        @echo ==== Creating $(SYSTEM).out from obj files ====
 $(LINK_TOOL) $(LINK_TOOL_OPTS) $(LFLAGS)  -o $@ $(LIB_FILES)
 @echo Created executable: $(SYSTEM)


$(C_OBJECTS) : $(C_FILES)
        @echo ===Building Source File $@...
 $(COMPILE_TOOL) $(COMPILE_TOOL_OPTS) $(CFLAGS) -o $@ -c $(@:.o=.c)

   

 

0 Kudos
Reply

2,710 Views
jbezem
Contributor III

And where's the reference to $(OBJ_FILES) in your linker command line, then? Maybe you hide it in some other variable, but I do not seem to recognize it.

 

FWIW,

 

Johan

0 Kudos
Reply

2,710 Views
RichTestardi
Senior Contributor II

I am not sure if this is exactly what you are asking, but in my Makefiles, I list the libraries objects twice, so that libraries can reference other libraries, out of order, like:

 

target: $(TARGET).elf$(TARGET).elf: $(LCFS) $(OBJECTS) $(OBJECTASMS) $(OBJECTLIBS) $(OBJECTLIBS) echo mwldmcf.exe -o $@ $+ >&2; \ "$(LD)" $(LDFLAGS) -o $@ $+

Maybe you need to list $(LFLAGS) or $@ more than once?

 

-- Rich

0 Kudos
Reply

2,710 Views
CW_user
Contributor I

The thing is I am directly using the libraries to link ,haven't generated object code

It keeps giving undefined symbol errors that were referenced from functions inside the library.

$(SYSTEM).elf: $(OBJ_FILES)
        @echo ==== Creating $(SYSTEM).out from obj files ====
 $(LINK_TOOL) $(LINK_TOOL_OPTS) $(LFLAGS)  -o $@ $(LIB_FILES)
 @echo Created executable: $(SYSTEM) 

 

Here is log from Make

 

==== Creating TEST.out from obj files ====
 C:/"Program Files"/Freescale/"CodeWarrior for MPC55xx V2.3"/PowerPC_EABI_Tools/Command_Line_Tools/mwldeppc -gdwarf-2 -fp off -char signed -proc Zen -nostdlib -srec -lcf MPC560xB_DEBUG.lcf -Map TEST.map -o TEST.elf Runtime.PPCEABI.VS.UC.a MSL_C.PPCEABI.bare.VS.UC.a
### C:/PROGRA~1/FREESC~1/CODEWA~1.3/POWERP~1/COMMAN~1/mwldeppc.exe Linker Error:
#   undefined: '__init_hardware'
#   Referenced from '__start' in Runtime.PPCEABI.VS.UC.a

 

0 Kudos
Reply

2,710 Views
RichTestardi
Senior Contributor II

Could it be you have to write the function __init_hardware()?  Or you have to find some other library that contains it.  I know in the coldfire world, you supply a routine (__initialize_hardware(), called from _startup()) to perform early hardware initialization, and it can be an empty function, but if you don't supply it a default routine is used.

 

I don't know about PPC, sorry.  It might be the linker needs an option to tell it to use the default routine.

 

If you were asking if CW could find the library for you, I don't know of any way to do that (and there are often multiple flavors of any given library, so you have to pick the right one based on the calling conventions in use, etc., as libraries built with different calling conventions are often incompatible).

 

Since you asked about command line tools, do you not get this error when building with the IDE?

 

I did find this on the web (at http://www.cse.uconn.edu/~zshi/course/cse268/refs/cw_manual.pdf), talking about a default init_hardware() function:

 

If your code is running standalone (without the debugger), you may need to include a
board initialization file. These files have the extension .asm and are in this directory:
CWInstall\PowerPC_EABI_Support\Runtime\Src
These files are included in source form, so you can modify them to work with other boards
or hardware configurations.
Each board initialization file includes a function named usr_init(). This is the function
you call to run the hardware initialization code. In the normal case, this would be put into
the __init_hardware() function in either the ppc_eabi_init.c or
ppc_eabi_init.cpp file. In fact, the default __init_hardware() function has a call
into usr_init(), but it is commented out. Remove the comment tokens to have your
program perform the hardware initializations.

Could there be a board initialization file you are missing? 

 

Sorry I cannot be of more help.

 

-- Rich

Message Edited by Rich T on 2009-03-31 04:37 PM
0 Kudos
Reply

2,710 Views
stanish
NXP Employee
NXP Employee

It seems the file "__ppc_eabi_init.c" is missing in your project. This file is default part of CodeWarrior IDE projects if created by Project Wizard and it includes several functions refferenced from __startup.c.

 

I'd suggest you to copy it from CodeWarrior install directory ("<CW install dir.>\PowerPC_EABI_Support\Runtime\Src\__ppc_eabi_init.c" ) into your source directory and also modify the makefile in order to take it into account during compilation/linking.

 

Stanish

Message Edited by stanish on 2009-04-01 01:18 PM
0 Kudos
Reply