Creating and Using a Library (*a) for STM32F4 MCU with GNU GCC Compiler

Download demo file stm32f4_digital_output_demo_stm32f4.7z

View table of content.

How to Create a Library (.a) File

Objective: Combine waijung_hwdrvlib.c and stm32f4_digital_output_demo.c into libcustom_lib.a.

It is assumed that the source code were generated with Waijung Blockset. Hence, all the source code, make file, and autoexec (.bat) file are automatically generated and available.

Step 1 Create object file ( *.o) from the source ( *.c) file

Example Command

D:\waijung\trunk\waijung\utils\gnu_tools_arm_embedded\bin\arm-none-eabi-gcc -I . -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffast-math -Wall -Wextra -Ofast -std=c99 -c waijung_hwdrvlib.c stm32f4_digital_output_demo.c

Do not forget to change your working directory from DOS command prompt to where the source file resides.


  1. D:\waijung\trunk\waijung\utils\gnu_tools_arm_embedded\bin\ is the path to GNU GCC bin files. In short, this is waijungroot\utils\gnu_tools_arm_embedded\bin\
  2. A lot of warning messages may appear. Ignore them for now.

As a result waijung_hwdrvlib.o and stm32f4_digital_output_demo.o are created.

Step 2 Convert the object ( *.o) file to a Library ( *.a) file

Example Command

D:\waijung\trunk\waijung\utils\gnu_tools_arm_embedded\bin\arm-none-eabi-ar -r libcustom_lib.a waijung_hwdrvlib.o stm32f4_digital_output_demo.o

combines waijung_hwdrvlib.o stm32f4_digital_output_demo.o in to libcustom_lib.a.

As a result libcustomcode.a is created.


The library file must always begin with the word “lib”.

How to Include the Library in the Build Process

Step 1 Modify the Make File

Modify the make file (*.mk) as shown below.


  1. Important!!! Ignore the prefix lib and the extension .a when including the library after the -l flag.
  2. -L. indicate that the path of the library is the current directory.

Step 2 Build

Build the system by running the bat file.

Example Command


The binary file is generated and can be loaded to the target as usual.