sebasthug
sebasthug

Reputation: 81

Function declaration in static library in C

I've a problem when I try to compile my program with my static library. I create the object file of my .c files whith gcc -c ft_putstr.c. Then I execute ar -rcs libft.a ft_putstr.o and then I make gcc main.c -L. -lft and I've

warning: implicit declaration of function 'ft_putstr' is invalid in C99.

The binary is created but I don't want this warning even if it's work like that. It works if I had the flag -std="c89" on GCC but I have tu use C99.

This is my main :

int main(void)
{
     ft_putstr("Bonjour");
     return (0);
}

This my ft_putstr.c :

#include <unistd.h>

    void    ft_putstr(char *str) 
    {
         (*str) ? write(1, str, 1), ft_putstr(str + 1) : 0; 
    }

Upvotes: 0

Views: 1897

Answers (1)

Jeegar Patel
Jeegar Patel

Reputation: 27210

You should include a header file which has a declaration like

void    ft_putstr(char *str);

or you can insert this line in your main.c

extern void    ft_putstr(char *str);

Upvotes: 5

Related Questions