Lighting Design Ideas for Living Room

Transform your living space with the latest lighting design ideas! Get expert advice on all the hottest styles for 2023 with this guide! The interior lighting design of your living room plays a…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




C Static Libraries

Why do we use libraries? Because they save us time. If all our object files would be spread apart around the disk, instead of on a singular archive, the linking phase of the compilation would take more time. Static libraries are linked to our program during the compilation, but are not relevant during runtime. Hence, once the library is linked we only need to run our program executable file.

The process to create a static library in C is pretty simple. First we compile all our files we want to include in our library, so that they are in object file format. Let’s say we have our files in .c extension. The below picture shows us the command and an example of how to compile our files:

Then we use a program called ar ( ‘archiver’) and the flags -rc . If the library has been created previously one can use the -r flag to tell the program to replace older object files with new ones. The r stands for ‘replace’ and the c for ‘create’. An example of how to execute this command can be seen below:

ar -rc libstatic.a objectfile1.o objectfile2.o objectfile3.o

After our libstatic.a has been created, there is a need to index it. We can do this running the following command:

ranlib libstatic.a

How to use a “C” static library in a program?

Now that we have our libstatic.a with object objectfile1.o, objectfile2.o and objectfile3.o inside we would want to link it to our program trough compilation. The way to do this is very simple. One just adds the library name to the list of object files given to the linker, this is done with the -l flag. Example:

gcc mainfile.o -L. -lstatic -o new

The . after the L flag tells that libraries can be found in the current directory.

Add a comment

Related posts:

Use Music to Up Your Running Game

LISTENING TO MUSIC while running may be an essential way to improve your game. This is the conclusion of the first study to look at the effect of listening to music playlists on endurance running…

Quantum Computing and Blockchain

In this series of articles starting here, I want to share some thoughts and research regarding what may mean the construction and massification of a quantum computer for current cryptography and in…

The Hustler Remixing Task

Twas a sunny day at which hour ‘Fast’ Eddie Felson and his valorous cousin, Charlie, entered a snooker bar to dare the county’s best pool player, Minnesota Fats. those gents hath played ov’r night…