1
votes

I want to create a static library libmylib.a from mylib.c/.h and link it to a project to use this library in bootloader code using the arm-none-eabi-gcc cross compiler in ubuntu 20.04 LTS.

I have an electronic engineering background, so I'm kind of new in this compiler and linker stuff.

What I know: I've been searching about this, and found out that '.a' are just packed '.o' files, and that's it. You can do it using ar in linux. I don't know how to manage the dependencies for this '.a' file, for example, or how to link it to the project.

What I want to know: I really want to understand how it works, to compile and generate the bin, elf or hex files using these static libraries for arm using the arm-none-eabi-gcc cross compiler (found some for linux), but I don't know how to search for this properly, how to learn it in a linear way. If you guys could help me on this I would be really grateful.

1
make an object (gcc) then add it to a library. then link the archive in with the project that wants to use it.old_timer
arm-none-eabi-arold_timer
thanks guys, not so complicated :)Tarcis Becher

1 Answers

1
votes

First you create your library objects. Let us say that you have a foo function written in foo.c, then you do:

arm-none-eabi-gcc -c foo.c

The -c options tells the compiler to stop after assembling and no go further.

Then you need to create the .a file

arm-none-eabi-ar -rc libfoo.a foo.o

this command creates a static library called libfoo.a

At the end you compile your main with:

arm-none-eabi-gcc -L. -lfoo main.c -o main

Note that in -l flag we don put "lib" and ".a", those are automagically added. The -L. flag tells gcc to look into the current folder for library files.