简体   繁体   中英

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 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; 
    }

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM