c - 这个 .h 正确吗?

标签 c

很奇怪我有这个错误:

/tmp/ccq0e479.o:main.c:(.text+0x1a): undefined reference to
`ft_putchar' collect2: error: ld returned 1 exit status

主.c :

#include "biblio.h"

int main(int argc, char** argv){

        ft_putchar(argv[1]);
        return 0;

}

ft_putchar.c :

#include <stdio.h>
#include "biblio.h"

    void ft_putchar (char* str){
            int i = 0;
            while (str[i] != '\0'){
                    write(1,str[i], 1);
                    i++;
            }
            write(1,'\0', 1);

    }

biblio.h

#ifndef biblio_ft
#define biblio_ft

void ft_putchar(char*);

#endif

最佳答案

只编译main.c是不够的,你需要编译这两个文件:

gcc main.c ft_putchar.c -o myprog

gcc -c main.c
gcc -c ft_putchar.c
gcc main.o ft_putchar.o -o myprog 

更多信息:Gcc tutorial

关于c - 这个 .h 正确吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37471961/

相关文章:

c - fcntl() 范围可见性行为?

c - glibc 检测到 realloc() : invalid next size: 0x

c++ - 哪个子树在 Avl 树删除中具有更高的优先级

c - 如何将字符串转换为c中的命令?

c - 导致崩溃的基本字符串比较

c - 正确的 fork() 和 pipe() 用于有多个 child 的单亲。我该怎么做?

c - Unix cat -n 命令实现

c - 删除字符串数组项并移动 c 中的其余项

c - 使用 SDL 时未定义对 WinMain@16 的引用

使用和不使用 -std=c99 的代码会产生不同的结果(UMAC AE 实现)