Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How is this gcc instruction being interpreted?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading