Sign in

Static Libraries in C

¿How to create and use?

This is where the libraries come into play (:

How do libraries work?

Caption 1.1 compilation process

Making a Library

void _puts(char *s)
{
int i;

for (i = 0; s[i] != 0; i++)
{
putchar(s[i]);
}

putchar('\n');
}
void _puts(char *s);
$ gcc -c _puts.c   // produces a _puts.o object file
$ ar -rc libholberton.a _puts.o
$ nm libholberton.a
// output
_puts.o
U putchar
000000000000000 T _puts

How to use them

int main(void)
{
_puts("\"At the end of the day, my goal was to be the best hacker\"\n\t- Kevin Mitnick");
return (0);
}
gcc main.c -L. -lholberton -o my_test

Now that everything went well, we have an executable file

./test
"At the end of the day, my goal was to be the best hacker"
- Kevin Mitnick

Software Engineer in progress

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store