我是Linux编程的新手,我尝试编译一个简单的测试程序。但在编译时出现了错误。将inc.c添加到文件中(在app:行中)也不起作用。如何正确地包含这个文件?
Makefile:
app: main.c inc.h
cc -o app main.c
终端:
make
cc -o app main.c
/tmp/ccGgdRNy.o: In function `main':
main.c:(.text+0x14): undefined reference to `test'
collect2: error: ld returned 1 exit status
make: *** [app] Error 1
main.c:
#include <stdio.h>
#include "inc.h"
int main()
{
printf("Kijken of deze **** werkt:\n");
test();
getchar();
return 0;
}
inc.h
#ifndef INCLUDE_H
#define INCLUDE_H
void test();
#endif
inc.c
#include <stdio.h>
void test()
{
printf("Blijkbaar wel!");
}
cc -c main.c inc.h
和cc -c inc.c inc.h
中要放置头文件? - btwiuse