C中静态库中的函数声明

seb*_*hug 0 c gcc static-libraries unix-ar compiler-warnings

当我尝试使用静态库编译程序时,我遇到了问题.我创建了我的.c文件的目标文件gcc -c ft_putstr.c.然后我执行ar -rcs libft.a ft_putstr.o,然后我做gcc main.c -L. -lft,我

警告:函数'ft_putstr'的隐式声明在C99中无效.

二进制文件已创建但我不想要这个警告,即使它是这样的.如果我-std="c89"在GCC上有旗帜但我使用C99就可以了.

这是我的主要内容:

int main(void)
{
     ft_putstr("Bonjour");
     return (0);
}
Run Code Online (Sandbox Code Playgroud)

这是我的ft_putstr.c:

#include <unistd.h>

    void    ft_putstr(char *str) 
    {
         (*str) ? write(1, str, 1), ft_putstr(str + 1) : 0; 
    }
Run Code Online (Sandbox Code Playgroud)

Jee*_*tel 5

你应该包含一个头文件,其中包含一个声明

void    ft_putstr(char *str);
Run Code Online (Sandbox Code Playgroud)

或者你可以在你的插入中插入这一行 main.c

extern void    ft_putstr(char *str);
Run Code Online (Sandbox Code Playgroud)