'Using a static library in c (.a file)

I am trying to create a static library using a shell script.

For creating the library I used following script:

gcc -c -Wall -Wextra -Werror *.c
ar -cr libft.a *.o

There are 5 different functions in 5 .c files.

Now I wanted to test the library and created a main.c file with this content:

#include "libft.a"

int     main(void)
{
    ft_putstr("hello");
}

Compiling the main.c (with gcc main.c) returns 419 warning and at least 20 errors looking something like this:

./libft.a:4:492: warning: null character ignored [-Wnull-character]
  ...<U+0000>UH<89><E5>H<83><EC><U+0010>@<88>}<FF><BF><U+0001><U+0000><U+0000><U+0000>H<8D>u...

Before this I was working with .h files which worked fine but this time I wasn't supposed to create a .h file so I don't what to do know.



Solution 1:[1]

When you compile your main.c, add the library name to it like this:

gcc main.c libft.a

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeremy Caney