0

My static library was compiled with all functions I have but when I'm using it, i'm getting an error:

warning: implicit declaration of function 'ft_putnbr' is invalid in C99 [-Wimplicit-function-declaration]

My source code:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int     main(void)
{
     int fd;

     fd = open("42", O_CREAT | O_WRONLY, S_IRUSR, S_IWUSR);
     ft_putnbr(fd);
     return (0);
}

I'm compiling with this option:

gcc main.c -L. -lft

My static library is named and contain ft_putnbr function: libft.a
But when I wrote: include "libft.h" it's working
Why it's not working without include "libft.h" ?

1 Answers1

1

Because static libraries are only read by the linker at the linking stage (and the static library doesn't contain its functions signatures anyway). The compiler needs to know what this function is at the compile stage. So you need to include the header file providing your function's signature.

MK.
  • 33,605
  • 18
  • 74
  • 111