Makefile

hello.out : hello.c
	gcc -o hello.out hello.c

(警告)没有声明

warning: implicit declaration of function ‘xxx’

hello.c

#include <stdio.h>
#include <stdlib.h>

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

    printf("hello\n");
    add();
    
	return EXIT_SUCCESS;
}

int add()
{

}
$ make
gcc -o hello.out hello.c
hello.c: In function ‘main’:
hello.c:8:5: warning: implicit declaration of function ‘add’ [-Wimplicit-function-declaration]
    8 |     add();
      |     ^~~

(报错)没有定义

undefined reference to `xxx'

hello.c

#include <stdio.h>
#include <stdlib.h>

int add();

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

    printf("hello\n");
    add();
    
	return EXIT_SUCCESS;
}
$ make
gcc -o hello.out hello.c
/usr/bin/ld: /tmp/ccKiQEUO.o: in function `main':
hello.c:(.text+0x25): undefined reference to `add'
collect2: error: ld returned 1 exit status
make: *** [Makefile:2:hello.out] 错误 1

(警告)没有声明 + (报错)没有定义

implicit declaration of function ‘xxx’

undefined reference to `xxx'

hello.c

#include <stdio.h>
#include <stdlib.h>

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

    printf("hello\n");
    add();
    
	return EXIT_SUCCESS;
}
$ make
gcc -o hello.out hello.c
hello.c: In function ‘main’:
hello.c:8:5: warning: implicit declaration of function ‘add’ [-Wimplicit-function-declaration]
    8 |     add();
      |     ^~~
/usr/bin/ld: /tmp/cc5tAiOm.o: in function `main':
hello.c:(.text+0x25): undefined reference to `add'
collect2: error: ld returned 1 exit status
make: *** [Makefile:2:hello.out] 错误 1

(报错)缺失分隔符

Makefile:2: *** 缺失分隔符。 停止。

Makefile

hello.out : hello.c
    gcc -o hello.out hello.c

gcc 前面为 4 个空格,而不是一个 table。

原因:command 必须以 Tab 键开头。