HOWTO: Add a static library file into S32DS GCC project

cancel
Showing results for 
Search instead for 
Did you mean: 

HOWTO: Add a static library file into S32DS GCC project

No ratings

HOWTO: Add a static library file into S32DS GCC project

This document describes two ways how to add a static library file (*.a) into your S32 Design Studio GCC project. These methods differs from each other in sense how a library update is reflected into project build process.

Adding a static library WITHOUT dependency to executable (elf) file

This approach assumes a library does not change. An update of the library does not trigger project rebuild process. If the library changes the project needs to be manually cleaned (assuming no other source file has changed) and next build links the updated library.

The path to the library and the library name shall be entered into Project Properties -> C/C++ Build -> Settings -> Standard S32DS C Linker -> Libraries

pastedImage_4.png

Please note that GCC adds prefix "lib" and the extension ".a"  to the library name entered into the above dialog by default.

GCC linker will search for the library file named: "libtestlib.a" in the folder "c:\my_libs" In the example above.

In case a library cannot be found the linker error occurs e.g. one depicted below. The linker library file name option "-ltestlib.a" is expanded into file name "libtestlib.a.a" which does not exist.

10:28:53 **** Incremental Build of configuration Debug for project S32K144_Project_with_library ****
make -j8 all 
Building target: S32K144_Project_with_library.elf
Executing target #5 S32K144_Project_with_library.elf
Invoking: Standard S32DS C Linker
arm-none-eabi-gcc -o "S32K144_Project_with_library.elf" "@S32K144_Project_with_library.args" 
c:/nxp/s32ds_arm_v2.0/cross_tools/gcc-arm-none-eabi-4_9/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: cannot find -ltestlib.a
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:49: S32K144_Project_with_library.elf] Error 1
10:28:54 Build Finished (took 1s.332ms)‍‍‍‍‍‍‍‍‍‍

For a custom library name add colon character ":" at the beginning of the library name to disable the default prefix/extension expansion.

GCC linker now searches for file name "testlib.lib" in the example below:

 

pastedImage_18.png

Adding a static library WITH dependency to executable (elf) file

If a static library has changed - "touched"  it is sometimes desired to trigger project rebuild. In this scenario the library shall be added into a different project dialog:

Project Properties -> C/C++ Build -> Settings -> Standard S32DS C Linker -> Miscellaneous -> Other objects

pastedImage_33.png

The items from "Other objects" list is propagated into USER_OBJS makefile variable which is prerequisite for auto-generated makefile rule that build the target (elf):

pastedImage_34.png

Enjoy linking static libraries in S32DS!

Comments

how to add a .o file into s32ds gcc project?

Hi Liu,

You can add an object file into linker in the same way as library file - Standard S32DS Linker -> Other Objects -> enter your .o file

Hope it helps.

Stan

Version history
Revision #:
2 of 2
Last update:
‎09-10-2020 02:11 AM
Updated by: