Link order config for Lib file

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

Link order config for Lib file

993 Views
zhangcindy
NXP Employee
NXP Employee

For CodeWarrior 11.1, how to config the link order for *.lib? Here I only find about the link order for *.c. Can CW11.1 support to config *.c and *.lib in specified order together?  It is easy to do it with CW6.3.

LinkOder.PNG

CW6.3.png

0 Kudos
1 Reply

983 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi

I did look into this for 8/16b, but, unless I am missing something, CW for MCU 10.2 does not allow changing the link order in exactly the same way as classic CW for S08 (6.x). With 10.2, one can only change the relative order of the external libraries – as opposed to modifying the relative order for project object files, or exchanging object files with external libraries in the link order.

We tested a project contains an example for S08. Its main() function calls two other functions: sum() - which is defined in an external library (Test.lib), and max() - which is defined in one of the project sources (p.c). This means that the project will need to be linked against Test.lib, as well as p_c.obj.
In order to find out what the link order looks like, we need to check argument file Project.args (which is where the linker takes its arguments from, according to the automatically generated makefile):

"$(ProjDirPath)/Project_Settings/Linker_Files/Project.prm" -M -ViewHidden -WmsgFob"%f%e:%l:%k:%d %m\n" -WmsgSd1100 -WmsgSd1912 -Add("$(ProjDirPath)/MC9S08AC8/Sources/main_c.obj" "$(ProjDirPath)/MC9S08AC8/Sources/p_c.obj" "$(ProjDirPath)/MC9S08AC8/Project_Settings/Startup_Code/start08_c.obj" "$(ProjDirPath)/MC9S08AC8/Lib/mc9s08ac8_c.obj" "$(MCUToolsBaseDirEnv)/lib/hc08c/lib/ansiis.lib" "$(ProjDirPath)/Lib/Test.lib")

Please notice that, apart from the project object files (*.obj), linking is also performed against two external libraries: ansiis.lib (the ANSI-C library) and test.lib (the user library which defines symbol ‘sum’). While it is indeed possible to change the relative order of ansiis.lib and Test.lib (i.e. place Test.lib before ansiis.lib in the link order), nothing can be done about the object files (i.e. we cannot exchange places between p_c.obj and main_c.obj, or p_c.obj and ansiis.lib, or p_c.obj and Test.lib, and so on).

In order to change the relative order for external libraries, you need to go to Properties -> Settings -> S08 Linker -> Input -> Libraries (where you can move a library up/down, depending on how you wish to change the link order). You cannot change the link order as a whole (object files included), unless you disable automatic makefile generation and manually update the linker argument file so as to force the desired order. This is a workaround, rather than a solution.

 

Hope this helps

Jun Zhang

0 Kudos