I downloaded libopencm3 (https://github.com/libopencm3/libopencm3) library and compiled it. It worked. I found a small project that uses this library and copied the instructions from its makefile.
all:
arm-none-eabi-gcc \
-Os \
-ggdb3 \
-mthumb \
-mcpu=cortex-m0 \
-msoft-float \
-Wall \
-Wextra \
-Wundef \
-Wshadow \
-Wredundant-decls \
-fno-common \
-ffunction-sections \
-fdata-sections \
-std=c11 \
-MD \
-DSTM32F0 \
-I./libopencm3/include \
-o main.o \
-c main.c
arm-none-eabi-gcc \
--static \
-nostartfiles \
-Tstm32f0.ld \
-mthumb \
-mcpu=cortex-m0 \
-msoft-float \
-ggdb3 \
-Wl,-Map=main.map \
-Wl,--cref \
-Wl,--gc-sections \
-L./libopencm3/lib \
main.o \
-lopencm3_stm32f0 \
-Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \
-o main.elf
I created a folder for the project, pasted libopencm3 folder inside it and compiled. It’s working, but I don’t understand how this part works:
-L./libopencm3/lib main.o -lopencm3_stm32f0
If I am right, it is instructing to find opencm3_stm32f0 library inside /libopencm3/lib, but inside that folder I found libopencm3_stm32f0.a instead.
I want to know why they changed the name and omitted the extension and it still worked.
>Solution :
This isn’t related to makefiles or to any specific library, or to embedded systems, so those tags on your question are not needed.
If you look up the -l option in the documentation of the linker, you’ll understand how it works.