あなたは間違ったルールを見ています。 Download.c
実際には正常にコンパイルされていますが、リンク段階が間違っています。
$ make
gcc -c -std = c99 Download.c #コンパイル
gcc Download.c -oプログラム #リンク
プログラムをリンクするmakeルールを修正します。おそらく次のようになります。
Program: a.o b.o c.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
あなたがそれにいる間、私はより完全なMakefileが次のようになることを提案します:
all: Program
clean:
rm -f Program *.o
.PHONY: all clean
# -c is implicit, you don't need it (it *shouldn't* be there)
# CC is also implicit, you don't need it
CFLAGS := -std=c99 -g -Wall -Wextra
Program: a.o b.o c.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
# Make will automatically generate the necessary commands
# You just need to name which headers each file depends on
# (You can make the dependencies automatic but this is simpler)
a.o: a.c header.h
b.o: b.c header.h header2.h
c.o: c.c header.h
それを間違える方法の例
リンカーフラグは実際にはかなり扱いにくいです!必ず上記の行を私が書いたとおりに入力してください。あなたが書いたものが同等であると思い込まないでください。間違っているため使用してはならないわずかに異なるコマンドの例を次に示します。
# WRONG: program must depend on *.o files, NOT *.c files
Program: a.c b.c c.c
$(CC) ...
# WRONG: -c should not be in CFLAGS
CFLAGS := -c -std=c99
Program: a.o b.o c.o
# WRONG: $(CFLAGS) should not be here
# you are NOT compiling, so they do not belong here
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
# WRONG: $(LIBS) MUST come at the end
# otherwise linker may fail to find symbols
$(CC) $(LDFLAGS) -o $@ $(LIBS) $^
# WRONG: do not list *.o files, use $^ instead
# otherwise it is easy to get typos here
$(CC) $(LDFLAGS) -o $@ a.o b.o c.o $(LIBS)
# WRONG: $(LDFLAGS) must be at the beginning
# it only applies to what comes after, so you
# MUST put it at the beginning
$(CC) -o $@ $(LDFLAGS) $^ $(LIBS)
# WRONG: -c flag disables linking
# but we are trying to link!
$(CC) $(LDFLAGS) -c -o $@ $^ $(LIBS)
# WRONG: use $(CC), not gcc
# Don't sabotage your ability to "make CC=clang" or "make CC=gcc-4.7"
gcc $(LDFLAGS) -o $@ $^ $(LIBS)
# WRONG: ld does not include libc by default!
ld $(LDFLAGS) -o $@ $^ $(LIBS)