このメイクファイルは私が期待どおりに動作しません。現在のディレクトリとサブディレクトリにある各.cファイルの.oファイルをビルドして、静的ライブラリに配置します。ただし、最初のファイルまたは2番目のファイルの後に$(INCS)の適用を停止します。 2つ目の.oファイルをビルドしようとすると、ビルド行に-Iパスが表示されず、そこにヘッダーファイルが見つからないという不満があります。物事を簡素化するために名前が一般化されています。私はWindows XPでcygwinを使用しています。私はcygwinツリーの下にないARMクロスコンパイラを使用しています。私はこのメイクファイルを回答hereに基づいています。 .cファイルは約2ダースしかないので、このように依存ファイルを作成するオーバーヘッドは大きな問題ではありません。このメイクファイルはすべてのオブジェクトに適用されないのはなぜですか?
# Project specific options
CC = my-cross-gcc
INCS := -I. -Iinc
INCS += -Imy/inc/path
CFLAGS := -Wall -fPIC -static -cross-compiler-specific-options
OUT := bin/libmylib.a
MKDIR:=mkdir -p
### Generic C makefile items below:
# Add .d to Make's recognized suffixes.
SUFFIXES += .d
NODEPS:=clean
#Find all the C files in this directory, recursively
SOURCES:=$(shell find . -name "*.c")
#These are the dependency files
DEPFILES:=$(patsubst %.c,%.d,$(SOURCES))
OBJS:= $(patsubst %.c,%.o,$(SOURCES))
#Don't create dependencies when we're cleaning, for instance
ifeq (0, $(words $(findstring $(MAKECMDGOALS), $(NODEPS))))
-include $(DEPFILES)
endif
#This is the rule for creating the dependency files
%.d: %.c
$(CC) $(INCS) $(CFLAGS) -MM -MT '$(patsubst %.c, %.o,$(patsubst %.c,%.o,$<))' $< > [email protected]
#This rule does the compilation
%.o: %.c %.d %.h
$(CC) $(INCS) $(CFLAGS) -o [email protected] -c $<
# Now create a static library
all: $(OBJS)
@$(MKDIR) bin
ar rcsvq $(OUT) $(OBJS)
clean:
rm -rf $(OBJS) $(OUT) $(DEPFILES)
はなぜこのメイクファイルないが適用されます$(INCS)以降の.oファイルをビルドするとき?どうすれば修正できますか?私はthirdfile.oを構築し、-Iパスを使用してgccの行のコマンドラインと型に行くとき
$ make all
my-cross-gcc -I. -Iinc -Imy/inc/path -<compiler options> -o firstfile.o -c firstfile.c
my-cross-gcc -I. -Iinc -Imy/inc/path -<compiler options> -o secondfile.o -c secondfile.c
my-cross-gcc -<compiler flags> -o thirdfile.o -c thirdfile.c
thirdfile.c:23:18: fatal error: myinc.h: No such file or directory
compilation terminated.
、オブジェクトファイルが正常に構築されています。出力はこれに似ています。
'firstfile.h'と' secondfile.h'はありますが、 'thirdfile.h'はありませんか? –
あなたの質問には関係ありませんが、あなたは依存ファイルをどこにも含めておらず、役に立たなくしているようです。 – interjay
interjay、私は入力したメイクファイルをあまり単純化してしまったようです。私はこれらの行を上に追加します。 – jasper77