gpt4 book ai didi

C Makefile 编译错误 - "linker input file unused because linking not done"

转载 作者:行者123 更新时间:2023-11-30 15:02:28 33 4
gpt4 key购买 nike

我的 C Makefile 遇到问题。

这是 bash 中 Makefile 的代码:

CC=gcc
CFLAGS=-g -Wall
CCLINK=$(CC)
OBJS=flight.o runway.o airport.o main.o
RM=rm -f

# Creating the executable (airport)
airport: $(OBJS)
$(CCLINK) -o airport $(OBJS)

# Creating object files using default rules
main.o: main.c airport.h ex2.h flight.h runway.h
airport.o: airport.c airport.h ex2.h flight.h runway.h
runway.o: runway.c runway.h ex2.h flight.h
flight.o: flight.c flight.h ex2.h

# Cleaning old files before new make
clean:
$(RM) airport *.o *.bak *~ "#"* core

当我创建文件时,它说:

make: `airport` is up to date.

之后 - 我可以在 bash 中调用“机场”,它可以让我按照我想要的方式输入一些输入。

但是-当我尝试检查“机场”是否由以下人员编译时:

gcc -g -Wall -c airport

我收到一条错误消息:

gcc: airport: linker input file unused because linking not done

有人知道可能是什么问题吗?

谢谢!加夫里尔。

最佳答案

Makefile 的目的是避免在源代码未更改的情况下重新编译文件;当发生这种情况时,make 表示该文件是最新的。

如果您想再次检查警告,这可能会很烦人。然后,只需调用 make 即可重新编译所有内容,输入

make clean ; make

Makefile 的另一个目标是避免自己键入容易出错的 gcc 命令。例如,在问题的末尾,您要求从可执行文件(选项-c)创建目标文件,这是错误的。制作目标文件的好方法是调用 make :

make airport.o

最后,要生成可执行文件,您可以键入

make airport

或者,由于 airport: 是第一个目标,因此输入

make

关于C Makefile 编译错误 - "linker input file unused because linking not done",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41055311/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com