我是Linux編程的新手我試圖編譯一個簡單的測試構造。但編譯時出現錯誤。添加inc.c(在app:行中)也不起作用。我應該如何包含正確的文件?Makefile include header
的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'中? – navigaid 2017-03-21 12:58:52