C ++入門:メイクファイルの簡単な要約でソース

C ++入門:メイクファイルの簡単な要約でソース


1.背景

  C ++プライマーmainfileソースは、基本的には3種類あり、現在は各命令をまとめるmainfile意味、mainfile MS_makefile_template、メインディレクトリの各章のmainfileです。

ホームディレクトリ

章のリスト

0002

2.1ホームディレクトリmainfile

  ホームディレクトリmainfileは、各章のサブディレクトリにジャンプするために使用され、次の、そしてNMAKE NMAKEクリーンNMAKEのクロバーによって3つのコマンドがコンパイルソースコード、削除.OBJ、.OBJと.exeの削除を実施しています。各コマンドの具体的な実装はmainfileサブディレクトリによって実現しました。

DIRS = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

all:  
	cd 1 && nmake -nologo 
	cd 2 && nmake -nologo 
	cd 3 && nmake -nologo 
	cd 4 && nmake -nologo 
	cd 5 && nmake -nologo 
	cd 6 && nmake -nologo 
	cd 7 && nmake -nologo 
	cd 8 && nmake -nologo 
	cd 9 && nmake -nologo
	cd 10 && nmake -nologo
	cd 11 && nmake -nologo
	cd 12 && nmake -nologo
	cd 13 && nmake -nologo 
	cd 14 && nmake -nologo 
	cd 15 && nmake -nologo 
	cd 16 && nmake -nologo 
	cd 17 && nmake -nologo 
	cd 18 && nmake -nologo 
	cd 19 && nmake -nologo 

clean: 
	cd 1 && nmake -nologo clean 
	cd 2 && nmake -nologo clean 
	cd 3 && nmake -nologo clean 
	cd 4 && nmake -nologo clean 
	cd 5 && nmake -nologo clean 
	cd 6 && nmake -nologo clean 
	cd 7 && nmake -nologo clean 
	cd 8 && nmake -nologo clean 
	cd 9 && nmake -nologo clean
	cd 10 && nmake -nologo clean
	cd 11 && nmake -nologo clean
	cd 12 && nmake -nologo clean
	cd 13 && nmake -nologo clean 
	cd 14 && nmake -nologo clean 
	cd 15 && nmake -nologo clean 
	cd 16 && nmake -nologo clean 
	cd 17 && nmake -nologo clean 
	cd 18 && nmake -nologo clean 
	cd 19 && nmake -nologo clean 

clobber: 
	cd 1 && nmake -nologo clobber 
	cd 2 && nmake -nologo clobber 
	cd 3 && nmake -nologo clobber 
	cd 4 && nmake -nologo clobber 
	cd 5 && nmake -nologo clobber 
	cd 6 && nmake -nologo clobber 
	cd 7 && nmake -nologo clobber 
	cd 8 && nmake -nologo clobber 
	cd 9 && nmake -nologo clobber
	cd 10 && nmake -nologo clobber
	cd 11 && nmake -nologo clobber
	cd 12 && nmake -nologo clobber
	cd 13 && nmake -nologo clobber 
	cd 14 && nmake -nologo clobber 
	cd 15 && nmake -nologo clobber 
	cd 16 && nmake -nologo clobber 
	cd 17 && nmake -nologo clobber 
	cd 18 && nmake -nologo clobber 
	cd 19 && nmake -nologo clobber 

ヒント:/ NOLOGO無効に著作権表示に使用。

2.2サブディレクトリのmakefile

  サブディレクトリのmakefileは、実際にMS_makefile_templateのホームディレクトリを引用しました。それはきれいなのnmakeのクロバーコマンドの3種類のnmakeサブディレクトリのmakefile NMAKE、および具体的な方法を提供します。
サブディレクトリmainfile内容:

# executable files for this directory
OBJECTS = add.exe add_item.exe add_item2.exe avg_price.exe \
		  for_ex.exe forcount.exe item_io.exe main_only.exe \
		  mysum.exe occurs.exe whilecount.exe \

# tells make to use the file "..\MS_makefile_template", which
# defines general rules for making .obj and .exe files
include ..\MS_makefile_template

add_item.obj add_item2.obj avg_price.obj item_io.obj: Sales_item.h

ヒント:「含ま... \ MS_makefile_templateは」ディレクトリにMS_makefile_templateファイルを再分配します。

mainfileとMS_makefile_template統合のサブディレクトリの内容(ノートは削除されました):

// OBJECTS代表子目录需要生成的文件,其中"\"代表换行
OBJECTS = add.exe add_item.exe add_item2.exe avg_price.exe \
		  for_ex.exe forcount.exe item_io.exe main_only.exe \
		  mysum.exe occurs.exe whilecount.exe \

// CPP指定编译器,这里使用cl.exe
CPP = cl
// CPPFLAGS代表编译时所带的参数,"/EHsc"用于指定异常处理,"/nologo"用于禁止版权声明,"/I.."用于引用上级目录,即主目录。
CPPFLAGS = /EHsc /nologo /I.. $(LOCFLAGS)
// LOCFLAGS代表编译时额外需要添加的章节目录,方便引用文件夹中相关头文件。
LOCFLAGS =

// 默认生成OBJECTS所包含的.exe
all: $(OBJECTS) 

// 第一行表示将源文件编译成目标文件,即.cpp编译.obj,
// 第二行代表编译命令,"CPP"代表编译器, "CPPFLAGS"代表编译参数,
// "/c"表示生成.obj,"$< "代表源文件,即.cpp。
.cpp.obj: 
	$(CPP) $(CPPFLAGS) /c $< 

// 第一行表示将源文件编译成目标文件,即.obj编译成.exe
// 第二行代表代表编译命令,"CPP"代表编译器, "CPPFLAGS"代表编译参数,"$< "代表源文件,即.obj。
.obj.exe:
	$(CPP) $(CPPFLAGS) $<

// 清除命令,主要删除*.obj
clean:
	del *.obj core *.stackdump

// 清除所有命令,clobber依赖于clean,除了删除*.exe ,还需执行clean命令
clobber: clean
	del *.exe 

// 以":"分隔,表示前面文件的编译需要引用后面文件。
add_item.obj add_item2.obj avg_price.obj item_io.obj: Sales_item.h

メイクファイルの実行結果

3.まとめ

  1. マルチファイルのコンパイルの実行のために、より効率的な利用のmakefile。
公開された77元の記事 ウォン称賛25 ビュー10000 +

おすすめ

転載: blog.csdn.net/qq_34801642/article/details/103831395