我的老师不是最好的解释C所以我有点麻烦了解makefile的连接。我已经添加了complex.c,complex.h和main.c的代码。我只是无法使用make命令编译它。我遵循了他传递的powerpoint的例子,我不明白为什么它没有变得复杂。C Makefile错误:ld返回1退出
生成文件
complex: main.o complex.o
gcc -o complex main.o complex.o
main.o: main.c complex.h
gcc -c main.c -lm
complex.o: complex.c complex.h
gcc -c complex.c -lm
clean:
rm*.o complex
ls
main.o
main.o: complex.h
gcc -c main.c
complex.o
complex.o: complex.h
gcc -c complex.c
错误
mason% make
gcc -o complex main.o complex.o
ld: fatal: file main.o: unknown file type
ld: fatal: file processing errors. No output written to complex
collect2: error: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `complex'
'gcc'不会将'main.o'识别为目标文件,这似乎很奇怪。你在使用什么环境(OS,&C)? – Dolda2000
@ Dolda2000我正在使用mac – struggling
您应该每次运行'make clean'。它看起来像'main.o'存在,但是是错误的系统或损坏(或不正确)。 –