ListWise

Simple. Powerful. Brilliant.. “ListWise” is published by Listwise HQ.

Smartphone

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




Static Libraries in C

A convenient alternative is to utilize a static library, which is a single archive that contains multiple object files. A static library is created with the ar command, and can only store object files (the command will check for the .o filetype before including them in the archive).

ar -rc lib[NAME].a *.o

To create a library, use the AR command as formatted above. If you do not name the static library with the “lib” prefix, the compiler will have problems identifying the archive as a static library during compilating. You can specify one or more object files, or take all the object files from the current directory with the *.c notation.

-r: Insert an object file (“member”) into the archive with replacement. Any previously existing members are deleted if their names match those being added.

-c: Create the archive. A warning is issued if the archive already exists.

-t: Displays a table listing the contents of the archive. By adding the v modifier, you can also see extended information about the members within the archive. You can also view the names of the files in the archive by using the nm command.

-s: Adds (or updates) an index to the archive. The index permits . An index helps speed up the linking process by ordering the symbols (functions, variables, etc.), and ensuring that the order will not matter during compilation (i.e., if there are two libraries with mutual dependencies). The nmlib command also performs the same function separately.

gcc new [NEWCODE].c -l[ARCHIVENAME] -o [EXECUTABLE NAME]

In order to compile a new .c file with an existing static library in the current directory, you need to pass the -l argument to GCC with the name of the archive, minus the “lib” prefix and “.a” postfix (e.g., for an archive called libholberton.a, gcc newcode.c -lholberton).

Add a comment

Related posts:

How to make XGBoost available on the PySpark Jupyter Notebook

This is a step by step tutorial on how to install XGBoost (an efficient implementation of gradient boosting) on the Jupyter notebook. Presequisites for this guide are pyspark and Jupyter installed on…

Art.

My mother is an artist. Sometimes I wonder: if she had the opportunities I have in the school that I go to now, would she have taken them? Would she put her art in the County Art Show? Or even take…

5 Books to Start 2020 on a Good Note

As the 2019 getting closer to an end, I looked back to all of the book that I read this year. As a professional and ex-entrepreneur, i find that my typical go-to book was more into business…