简体   繁体   English

gcc,makefile没有正确链接

[英]gcc, makefile does not link correctly

I have this makefile: 我有这个makefile:

CC=gcc
CFLAGS= -c -Wall -std=c99 -ggdb

all: plan

plan: plan.o graph.o
    $(CC) $(CFLAGS) plan.o graph.o -o plan

plan.o: plan.c graph.h
    $(CC) $(CFLAGS) plan.c

graph.o: graph.c graph.h
    $(CC) $(CFLAGS) graph.c

run: all
    ./plan

when I run make, gcc give me the message "linker input file unused because linking not done", what does it mean by that? 当我运行make时,gcc给我的消息“链接器输入文件未使用,因为链接未完成”,这是什么意思?

The -c option means: -c选项意味着:

Compile or assemble the source files, but do not link. 编译或汇编源文件,但不要链接。 The linking stage simply is not done. 链接阶段根本没有完成。 The ultimate output is in the form of an object file for each source file. 最终输出是每个源文件的目标文件的形式。

You should not use that option when building. 在构建时不应使用该选项。

See gcc man gcc man

Update 更新

For the plan target, do not use the CFLAGS: 对于计划目标,请勿使用CFLAGS:

plan: plan.o graph.o
    $(CC) -Wall -std=c99 -ggdb plan.o graph.o -o plan

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM