很奇怪我有这个错误:
/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/