The Famed Technical Interview

Many bootcamp grads and college students want careers in software engineering, but never did a tech interview. This article will teach you about it.

Smartphone

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




How to use static libraries in C and be even faster

We can still saving time in “C” when we are creating a program with many dependencies of files, where are located all the needed functions. As the native libraries (eg. stdio), we can create own libraries.

In Unix system there are two kind of libraries: static and dynamic. In this post we only talk about static libraries.

When we have several files in our project, the compilation and linking time increase, so we have to list all the needed files. If we use a library there is needed a single entity in a linking phase.

This have another avantage when is needed the same files to different projects. We can use just the same library to other projects, too.

In the estatic library all files (better called “objects”) are linked to the program during the linking phase of compilation. So, the static library is a collection of objects that are linked to program, and only will be needed in linked phase, but aren’t needed in runtime phase.

That means that if we change or delete one file, the program still working. So the executable file doesn’t have dependencies. Only change if we compile again.

In a dynamic library (called shared library, too) the object files are linked to program but aren’t inserted in the executable file, so there are dependencies.

To create a library is needed all each Assembly files, that can be created in GCC with the option “-c”:

If we have several files with wildcards the process es faster. See article: what about widlcard on shell.

This command create a output file (.o) for each file finished with “.c” in current directory.

Now, the library could be created with the command “ar”. For a library called “libmaylibrary.a”:

Where:

This could be faster with wildcards, too.

We can verify the content of library with the command “ar -t”.

This will show the list of objects inside library.

If we want to know the symbols of each object, we can use the command “nm”.

After is time to make a index of library.

For use library is necessary make indexing of library. This is used by the compiler to speed up lookup inside the library.

The command “ranlib” is useful for that.

Now, we going to link the library with the executable file. This could be done with GCC, too.

Where:

With all the previous steps, we can create our library and link it with a executable file, this all we need to still be faster in development with “C”.

Add a comment

Related posts:

10 Best Project Tracking Software In 2020

This article will help you quickly compare and evaluate the best project management software with time tracking and other project tracking tools. Project tracking software can be used to gauge where…

Shephard Smith Leaves the Fox News Channel on TV.

Shep Smith has left Fox. This means it is all mean fake news all of the time with Fox and Friends, Doctor Laura Ingram and Shawn Hannity. That was the work of Roger Ailes and he also helped put Trump…

BLACK FRIDAY CrowdTokenCards SALE

Sergey from Russia purchased already more than 10 CrowdTokenCards and is actually on 5th place of BountyContest Leaderboard. Do you want to be in TOP10 of BountyRanking as well? Do you want to get…