免费高清特黄a大片,九一h片在线免费看,a免费国产一级特黄aa大,国产精品国产主播在线观看,成人精品一区久久久久,一级特黄aa大片,俄罗斯无遮挡一级毛片

分享

向大家推薦一個(gè)C/C 通用Makefile...

 sdyjmc 2010-10-11
精華帖 (5) :: 良好帖 (0) :: 新手帖 (0) :: 隱藏帖 (1)
作者 正文
  • lpn520
  • 等級(jí): 初級(jí)會(huì)員
  • 性別:
  • 文章: 55
  • 積分: 60
  • 來(lái)自: 杭州
   發(fā)表時(shí)間:2010-09-29   最后修改:2010-09-29

本文推薦了一個(gè)用于對(duì) C/C++ 程序進(jìn)行編譯和連接以產(chǎn)生可執(zhí)行程序的通用 Makefile。 

在 使用 Makefile 之前,只需對(duì)它進(jìn)行一些簡(jiǎn)單的設(shè)置即可;而且一經(jīng)設(shè)置,即使以后對(duì)源程序文件有所增減一般也不再需要改動(dòng) Makefile。因 此,即便是一個(gè)沒(méi)有學(xué)習(xí)過(guò) Makefile 書(shū)寫(xiě)規(guī)則的人,也可以為自己的 C/C++ 程序快速建立一個(gè)可工作的 Makefile。 

這個(gè) Makefile 可以在 GNU Make 和 GCC 編譯器下正常工作。但是不能保證對(duì)于其它版本的 Make 和編譯器也能正常工作。

此 Makefile 的使用方法如下:

程序目錄的組織 
  盡量將自己的源程序集中在一個(gè)目錄中,并且把 Makefile 和源程序放在一起,這樣用起來(lái)比較方便。當(dāng)然,也可以將源程序分類存放在不同的目錄中。 
在程序目錄中創(chuàng)建一個(gè)名為 Makefile 的文本文件,將后面列出的 Makefile 的內(nèi)容復(fù)制到這個(gè)文件中。(注意:在復(fù)制的過(guò)程 中,Makfile 中各命令前面的 Tab 字符有可能被轉(zhuǎn)換成若干個(gè)空格。這種情況下需要把 Makefile 命令前面的這些空格替換為一 個(gè) Tab。) 
  將當(dāng)前工作目錄切換到 Makefile 所在的目錄。目前,這個(gè) Makefile 只支持在當(dāng)前目錄中的調(diào)用,不支持當(dāng)前目錄和 Makefile 所在的路徑不是同一目錄的情況。

指定可執(zhí)行文件 
  程序編譯和連接成功后產(chǎn)生的可執(zhí)行文件在 Makefile 中的 PROGRAM 變量中設(shè)定。這一項(xiàng)不能為空。為自己程序的可執(zhí)行文件起一個(gè)有意義的名子吧。

指定源程序 
  要編譯的源程序由其所在的路徑和文件的擴(kuò)展名兩項(xiàng)來(lái)確定。由于頭文件是通過(guò)包含來(lái)使用的,所以在這里說(shuō)的源程序不應(yīng)包含頭文件。 
  程序所在的路徑在 SRCDIRS 中設(shè)定。如果源程序分布在不同的目錄中,那么需要在 SRCDIRS 中一一指定,并且路徑名之間用空格分隔。 
在 SRCEXTS 中指定程序中使用的文件類型。C/C++ 程序的擴(kuò)展名一般有比較固定的幾種形 式:.c、.C、.cc、.cpp、.CPP、.c++、.cp、或者.cxx(參見(jiàn) man gcc)。擴(kuò)展名決定了程序是 C 還是 C++ 程 序:.c 是 C 程序,其它擴(kuò)展名表示 C++ 程序。一般固定使用其中的一種擴(kuò)展名即可。但是也有可能需要使用多種擴(kuò)展名,這可以 在 SOURCE_EXT 中一一指定,各個(gè)擴(kuò)展名之間用空格分隔。 
  雖然并不常用,但是 C 程序也可以被作為 C++ 程序編譯。這可以通過(guò)在 Makefile 中設(shè)置 CC = $(CXX) 和 CFLAGS = $(CXXFLAGS) 兩項(xiàng)即可實(shí)現(xiàn)。 
  這個(gè) Makefile 支持 C、C++ 以及 C/C++ 混合三種編譯方式:

  如果只指定 .c 擴(kuò)展名,那么這是一個(gè) C 程序,用 $(CC) 表示的編譯命令進(jìn)行編譯和連接。

  如果指定的是除 .c 之外的其它擴(kuò)展名(如 .cc、.cpp、.cxx 等),那么這是一個(gè) C++ 程序,用 $(CXX) 進(jìn)行編譯和連接。
  如果既指定了 .c,又指定了其它 C++ 擴(kuò)展名,那么這是 C/C++ 混合程序,將用 $(CC) 編譯其中的 C 程序,用 $(CXX) 編譯其中的 C++ 程序,最后再用 $(CXX) 連接程序。 
  這些工作都是 make 根據(jù)在 Makefile 中提供的程序文件類型(擴(kuò)展名)自動(dòng)判斷進(jìn)行的,不需要用戶干預(yù)。

指定編譯選項(xiàng) 
  編譯選項(xiàng)由三部分組成:預(yù)處理選項(xiàng)、編譯選項(xiàng)以及連接選項(xiàng),分別由 CPPFLAGS、CFLAGS與CXXFLAGS、LDFLAGS 指定。 
  CPPFLAGS 選項(xiàng)可參考 C 預(yù)處理命令 cpp 的說(shuō)明,但是注意不能包含 -M 以及和 -M 有關(guān)的選項(xiàng)。如果是 C/C++ 混合編程,也可以在這里設(shè)置 C/C++ 的一些共同的編譯選項(xiàng)。 
CFLAGS 和 CXXFLAGS 兩個(gè)變量通常用來(lái)指定編譯選項(xiàng)。前者僅僅用于指定 C 程序的編譯選項(xiàng),后者僅僅用于指定 C++ 程序的編譯選 項(xiàng)。其實(shí)也可以在兩個(gè)變量中指定一些預(yù)處理選項(xiàng)(即一些本來(lái)應(yīng)該放在 CPPFLAGS 中的選項(xiàng)),和 CPPFLAGS 并沒(méi)有明確的界限。 
  連接選項(xiàng)在 LDFLAGS 中指定。如果只使用 C/C++ 標(biāo)準(zhǔn)庫(kù),一般沒(méi)有必要設(shè)置。如果使用了非標(biāo)準(zhǔn)庫(kù),應(yīng)該在這里指定連接需要的選項(xiàng),如庫(kù)所在的路徑、庫(kù)名以及其它聯(lián)接選項(xiàng)。 
現(xiàn)在的庫(kù)一般都提供了一個(gè)相應(yīng)的 .pc 文件來(lái)記錄使用庫(kù)所需要的預(yù)編譯選項(xiàng)、編譯選項(xiàng)和連接選項(xiàng)等信息,通過(guò) pkg-config 可以動(dòng)態(tài)提取 這些選項(xiàng)。與由用戶顯式指定各個(gè)選項(xiàng)相比,使用 pkg-config 來(lái)訪問(wèn)庫(kù)提供的選項(xiàng)更方便、更具通用性。在后面可以看到一個(gè) GTK+ 程序的例 子,其編譯和連接選項(xiàng)的指定就是用 pkg-config 實(shí)現(xiàn)的。

編譯和連接

  上面的各項(xiàng)設(shè)置好之后保存 Makefile 文件。執(zhí)行 make 命令,程序就開(kāi)始編譯了。 
  命令 make 會(huì)根據(jù) Makefile 中設(shè)置好的路徑和文件類型搜索源程序文件,然后根據(jù)文件的類型調(diào)用相應(yīng)的編譯命令、使用相應(yīng)的編譯選項(xiàng)對(duì)程序進(jìn)行編譯。 
  編譯成功之后程序的連接會(huì)自動(dòng)進(jìn)行。如果沒(méi)有錯(cuò)誤的話最終會(huì)產(chǎn)生程序的可執(zhí)行文件。 
  注意:在對(duì)程序編譯之后,會(huì)產(chǎn)生和源程序文件一一對(duì)應(yīng)的 .d 文件。這是表示依賴關(guān)系的文件,通過(guò)它們 make 決定在源程序文件變動(dòng)之后要進(jìn)行哪些更新。為每一個(gè)源程序文件建立相應(yīng)的 .d 文件這也是 GNU Make 推薦的方式。

Makefile 目標(biāo)(Targets)

下面是關(guān)于這個(gè) Makefile 提供的目標(biāo)以及它所完成的功能:

make 
編譯和連接程序。相當(dāng)于 make all。

make objs 
僅僅編譯程序產(chǎn)生 .o 目標(biāo)文件,不進(jìn)行連接(一般很少單獨(dú)使用)。

make clean 
刪除編譯產(chǎn)生的目標(biāo)文件和依賴文件。

make cleanall 
刪除目標(biāo)文件、依賴文件以及可執(zhí)行文件。

make rebuild 
重新編譯和連接程序。相當(dāng)于 make clean && make all。

關(guān)于這個(gè) Makefile 的實(shí)現(xiàn)原理不準(zhǔn)備詳細(xì)解釋了。如果有興趣的話,可參考文末列出的“參考資料”。

 

Makefile 的內(nèi)容如下: 

C代碼
  1. #############################################################  
  2. # Generic Makefile for C/C++ Program  
  3. #  
  4. # License: GPL (General Public License)  
  5. # Author:  whyglinux <whyglinux AT gmail DOT com>  
  6. # Date:    2006/03/04 (version 0.1)  
  7. #          2007/03/24 (version 0.2)  
  8. #          2007/04/09 (version 0.3)  
  9. #          2007/06/26 (version 0.4)  
  10. #          2008/04/05 (version 0.5)  
  11. #  
  12. # Description:  
  13. # ------------  
  14. # This is an easily customizable makefile template. The purpose is to  
  15. # provide an instant building environment for C/C++ programs.  
  16. #  
  17. # It searches all the C/C++ source files in the specified directories,  
  18. # makes dependencies, compiles and links to form an executable.  
  19. #  
  20. # Besides its default ability to build C/C++ programs which use only  
  21. # standard C/C++ libraries, you can customize the Makefile to build  
  22. # those using other libraries. Once done, without any changes you can  
  23. # then build programs using the same or less libraries, even if source  
  24. # files are renamed, added or removed. Therefore, it is particularly  
  25. # convenient to use it to build codes for experimental or study use.  
  26. #  
  27. # GNU make is expected to use the Makefile. Other versions of makes  
  28. # may or may not work.  
  29. #  
  30. # Usage:  
  31. # ------  
  32. # 1. Copy the Makefile to your program directory.  
  33. # 2. Customize in the "Customizable Section" only if necessary:  
  34. #    * to use non-standard C/C++ libraries, set pre-processor or compiler  
  35. #      options to <MY_CFLAGS> and linker ones to <MY_LIBS>  
  36. #      (See Makefile.gtk+-2.0 for an example)  
  37. #    * to search sources in more directories, set to <SRCDIRS>  
  38. #    * to specify your favorite program name, set to <PROGRAM>  
  39. # 3. Type make to start building your program.  
  40. #  
  41. # Make Target:  
  42. # ------------  
  43. # The Makefile provides the following targets to make:  
  44. #   $ make           compile and link  
  45. #   $ make NODEP=yes compile and link without generating dependencies  
  46. #   $ make objs      compile only (no linking)  
  47. #   $ make tags      create tags for Emacs editor  
  48. #   $ make ctags     create ctags for VI editor  
  49. #   $ make clean     clean objects and the executable file  
  50. #   $ make distclean clean objects, the executable and dependencies  
  51. #   $ make help      get the usage of the makefile  
  52. #  
  53. #===========================================================================  
  54.   
  55. ## Customizable Section: adapt those variables to suit your program.  
  56. ##==========================================================================  
  57.   
  58. # The pre-processor and compiler options.  
  59. MY_CFLAGS =  
  60.   
  61. # The linker options.  
  62. MY_LIBS   =  
  63.   
  64. # The pre-processor options used by the cpp (man cpp for more).  
  65. CPPFLAGS  = -Wall  
  66.   
  67. # The options used in linking as well as in any direct use of ld.  
  68. LDFLAGS   =  
  69.   
  70. # The directories in which source files reside.  
  71. # If not specified, only the current directory will be serached.  
  72. SRCDIRS   =  
  73.   
  74. # The executable file name.  
  75. # If not specified, current directory name or `a.out' will be used.  
  76. PROGRAM   =  
  77.   
  78. ## Implicit Section: change the following only when necessary.  
  79. ##==========================================================================  
  80.   
  81. # The source file types (headers excluded).  
  82. # .c indicates C source files, and others C++ ones.  
  83. SRCEXTS = .c .C .cc .cpp .CPP .c++ .cxx .cp  
  84.   
  85. # The header file types.  
  86. HDREXTS = .h .H .hh .hpp .HPP .h++ .hxx .hp  
  87.   
  88. # The pre-processor and compiler options.  
  89. # Users can override those variables from the command line.  
  90. CFLAGS  = -g -O2  
  91. CXXFLAGS= -g -O2  
  92.   
  93. # The C program compiler.  
  94. #CC     = gcc  
  95.   
  96. # The C++ program compiler.  
  97. #CXX    = g++  
  98.   
  99. # Un-comment the following line to compile C programs as C++ ones.  
  100. #CC     = $(CXX)  
  101.   
  102. # The command used to delete file.  
  103. #RM     = rm -f  
  104.   
  105. ETAGS = etags  
  106. ETAGSFLAGS =  
  107.   
  108. CTAGS = ctags  
  109. CTAGSFLAGS =  
  110.   
  111. ## Stable Section: usually no need to be changed. But you can add more.  
  112. ##==========================================================================  
  113. SHELL   = /bin/sh  
  114. EMPTY   =  
  115. SPACE   = $(EMPTY) $(EMPTY)  
  116. ifeq ($(PROGRAM),)  
  117.   CUR_PATH_NAMES = $(subst /,$(SPACE),$(subst $(SPACE),_,$(CURDIR)))  
  118.   PROGRAM = $(word $(words $(CUR_PATH_NAMES)),$(CUR_PATH_NAMES))  
  119.   ifeq ($(PROGRAM),)  
  120.     PROGRAM = a.out  
  121.   endif  
  122. endif  
  123. ifeq ($(SRCDIRS),)  
  124.   SRCDIRS = .  
  125. endif  
  126. SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))  
  127. HEADERS = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(HDREXTS))))  
  128. SRC_CXX = $(filter-out %.c,$(SOURCES))  
  129. OBJS    = $(addsuffix .o, $(basename $(SOURCES)))  
  130. DEPS    = $(OBJS:.o=.d)  
  131.   
  132. ## Define some useful variables.  
  133. DEP_OPT = $(shell if `$(CC) --version | grep "GCC" >/dev/null`; then \  
  134.                   echo "-MM -MP"else echo "-M"; fi )  
  135. DEPEND      = $(CC)  $(DEP_OPT)  $(MY_CFLAGS) $(CFLAGS) $(CPPFLAGS)  
  136. DEPEND.d    = $(subst -g ,,$(DEPEND))  
  137. COMPILE.c   = $(CC)  $(MY_CFLAGS) $(CFLAGS)   $(CPPFLAGS) -c  
  138. COMPILE.cxx = $(CXX) $(MY_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c  
  139. LINK.c      = $(CC)  $(MY_CFLAGS) $(CFLAGS)   $(CPPFLAGS) $(LDFLAGS)  
  140. LINK.cxx    = $(CXX) $(MY_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)  
  141.   
  142. .PHONY: all objs tags ctags clean distclean help show  
  143.   
  144. # Delete the default suffixes  
  145. .SUFFIXES:  
  146.   
  147. all: $(PROGRAM)  
  148.   
  149. # Rules for creating dependency files (.d).  
  150. #------------------------------------------  
  151.   
  152. %.d:%.c  
  153.     @echo -n $(dir $<) > $@  
  154.     @$(DEPEND.d) $< >> $@  
  155.   
  156. %.d:%.C  
  157.     @echo -n $(dir $<) > $@  
  158.     @$(DEPEND.d) $< >> $@  
  159.   
  160. %.d:%.cc  
  161.     @echo -n $(dir $<) > $@  
  162.     @$(DEPEND.d) $< >> $@  
  163.   
  164. %.d:%.cpp  
  165.     @echo -n $(dir $<) > $@  
  166.     @$(DEPEND.d) $< >> $@  
  167.   
  168. %.d:%.CPP  
  169.     @echo -n $(dir $<) > $@  
  170.     @$(DEPEND.d) $< >> $@  
  171.   
  172. %.d:%.c++  
  173.     @echo -n $(dir $<) > $@  
  174.     @$(DEPEND.d) $< >> $@  
  175.   
  176. %.d:%.cp  
  177.     @echo -n $(dir $<) > $@  
  178.     @$(DEPEND.d) $< >> $@  
  179.   
  180. %.d:%.cxx  
  181.     @echo -n $(dir $<) > $@  
  182.     @$(DEPEND.d) $< >> $@  
  183.   
  184. # Rules for generating object files (.o).  
  185. #----------------------------------------  
  186. objs:$(OBJS)  
  187.   
  188. %.o:%.c  
  189.     $(COMPILE.c) $< -o $@  
  190.   
  191. %.o:%.C  
  192.     $(COMPILE.cxx) $< -o $@  
  193.   
  194. %.o:%.cc  
  195.     $(COMPILE.cxx) $< -o $@  
  196.   
  197. %.o:%.cpp  
  198.     $(COMPILE.cxx) $< -o $@  
  199.   
  200. %.o:%.CPP  
  201.     $(COMPILE.cxx) $< -o $@  
  202.   
  203. %.o:%.c++  
  204.     $(COMPILE.cxx) $< -o $@  
  205.   
  206. %.o:%.cp  
  207.     $(COMPILE.cxx) $< -o $@  
  208.   
  209. %.o:%.cxx  
  210.     $(COMPILE.cxx) $< -o $@  
  211.   
  212. # Rules for generating the tags.  
  213. #-------------------------------------  
  214. tags: $(HEADERS) $(SOURCES)  
  215.     $(ETAGS) $(ETAGSFLAGS) $(HEADERS) $(SOURCES)  
  216.   
  217. ctags: $(HEADERS) $(SOURCES)  
  218.     $(CTAGS) $(CTAGSFLAGS) $(HEADERS) $(SOURCES)  
  219.   
  220. # Rules for generating the executable.  
  221. #-------------------------------------  
  222. $(PROGRAM):$(OBJS)  
  223. ifeq ($(SRC_CXX),)              # C program  
  224.     $(LINK.c)   $(OBJS) $(MY_LIBS) -o $@  
  225.     @echo Type ./$@ to execute the program.  
  226. else                            # C++ program  
  227.     $(LINK.cxx) $(OBJS) $(MY_LIBS) -o $@  
  228.     @echo Type ./$@ to execute the program.  
  229. endif  
  230.   
  231. ifndef NODEP  
  232. ifneq ($(DEPS),)  
  233.   sinclude $(DEPS)  
  234. endif  
  235. endif  
  236.   
  237. clean:  
  238.     $(RM) $(OBJS) $(PROGRAM) $(PROGRAM).exe  
  239.   
  240. distclean: clean  
  241.     $(RM) $(DEPS) TAGS  
  242.   
  243. # Show help.  
  244. help:  
  245.     @echo 'Generic Makefile for C/C++ Programs (gcmakefile) version 0.5'  
  246.     @echo 'Copyright (C) 2007, 2008 whyglinux <whyglinux@hotmail.com>'  
  247.     @echo  
  248.     @echo 'Usage: make [TARGET]'  
  249.     @echo 'TARGETS:'  
  250.     @echo '  all       (=make) compile and link.'  
  251.     @echo '  NODEP=yes make without generating dependencies.'  
  252.     @echo '  objs      compile only (no linking).'  
  253.     @echo '  tags      create tags for Emacs editor.'  
  254.     @echo '  ctags     create ctags for VI editor.'  
  255.     @echo '  clean     clean objects and the executable file.'  
  256.     @echo '  distclean clean objects, the executable and dependencies.'  
  257.     @echo '  show      show variables (for debug use only).'  
  258.     @echo '  help      print this message.'  
  259.     @echo  
  260.     @echo 'Report bugs to <whyglinux AT gmail DOT com>.'  
  261.   
  262. # Show variables (for debug use only.)  
  263. show:  
  264.     @echo 'PROGRAM     :' $(PROGRAM)  
  265.     @echo 'SRCDIRS     :' $(SRCDIRS)  
  266.     @echo 'HEADERS     :' $(HEADERS)  
  267.     @echo 'SOURCES     :' $(SOURCES)  
  268.     @echo 'SRC_CXX     :' $(SRC_CXX)  
  269.     @echo 'OBJS        :' $(OBJS)  
  270.     @echo 'DEPS        :' $(DEPS)  
  271.     @echo 'DEPEND      :' $(DEPEND)  
  272.     @echo 'COMPILE.c   :' $(COMPILE.c)  
  273.     @echo 'COMPILE.cxx :' $(COMPILE.cxx)  
  274.     @echo 'link.c      :' $(LINK.c)  
  275.     @echo 'link.cxx    :' $(LINK.cxx)  
  276.   
  277. ## End of the Makefile ##  Suggestions are welcome  ## All rights reserved ##  
  278. ##############################################################  
 

 

 

下面提供兩個(gè)例子來(lái)具體說(shuō)明上面 Makefile 的用法。 

例一 Hello World 程序

這個(gè)程序的功能是輸出 Hello, world! 這樣一行文字。由 hello.h、hello.c、main.cxx 三個(gè)文件組成。前兩個(gè)文件是 C 程序,后一個(gè)是 C++ 程序,因此這是一個(gè) C 和 C++ 混編程序。

C代碼
  1. /* File name: hello.h 
  2.  * C header file 
  3.  */  
  4.   
  5. #ifndef HELLO_H  
  6. #define HELLO_H  
  7.   
  8. #ifdef __cplusplus  
  9. extern "C" {  
  10. #endif  
  11.   
  12.   void print_hello();  
  13. #ifdef __cplusplus  
  14. }  
  15.   
  16. #endif  
  17. #endif  
  18.   
  19.   
  20. /* File name: hello.c 
  21.  * C source file. 
  22.  */  
  23.   
  24. #include "hello.h"  
  25. #include <stdio.h>  
  26.   
  27. void print_hello()  
  28. {  
  29.   puts( "Hello, world!" );  
  30. }  
  31.   
  32.   
  33. /* File name: main.cxx 
  34.  * C++ source file. 
  35.  */  
  36.   
  37. #include "hello.h"  
  38.   
  39. int main()  
  40. {  
  41.   print_hello();  
  42.   return 0;  
  43. }  
 

 

建立一個(gè)新的目錄,然后把這三個(gè)文件拷貝到目錄中,也把 Makefile 文件拷貝到目錄中。之后,對(duì) Makefile 的相關(guān)項(xiàng)目進(jìn)行如下設(shè)置: 

PROGRAM   := hello      # 設(shè)置運(yùn)行程序名

SRCDIRS   := .          # 源程序位于當(dāng)前目錄下

SRCEXTS   := .c .cxx    # 源程序文件有 .c 和 .cxx 兩種類型

CFLAGS    := -g         # 為 C 目標(biāo)程序包含 GDB 可用的調(diào)試信息

CXXFLAGS  := -g         # 為 C++ 目標(biāo)程序包含 GDB 可用的調(diào)試信息 

  由于這個(gè)簡(jiǎn)單的程序只使用了 C 標(biāo)準(zhǔn)庫(kù)的函數(shù)(puts),所以對(duì)于 CFLAGS 和 CXXFLAGS 沒(méi)有過(guò)多的要求,LDFLAGS 和 CPPFLAGS 選項(xiàng)也無(wú)需設(shè)置。 

  經(jīng)過(guò)上面的設(shè)置之后,執(zhí)行 make 命令就可以編譯程序了。如果沒(méi)有錯(cuò)誤出現(xiàn)的話,./hello  就可以運(yùn)行程序了。

  如果修改了源程序的話,可以看到只有和修改有關(guān)的源文件被編譯。也可以再為程序添加新的源文件,只要它們的擴(kuò)展名是已經(jīng)在 Makefile 中設(shè)置過(guò)的,那么就沒(méi)有必要修改 Makefile。 

 

例二 GTK+ 版 Hello World 程序

  這個(gè) GTK+ 2.0 版 的 Hello World 程序可以從下面的網(wǎng)址上得到:http://www./tutorial/c58.html#SEC- HELLOWORLD。當(dāng)然,要編譯 GTK+ 程序,還需要你的系統(tǒng)上已經(jīng)安裝好了 GTK+。 
  跟第一個(gè)例子一樣,單獨(dú)創(chuàng)建一個(gè)新的目錄,把上面網(wǎng)頁(yè)中提供的程序保存為 main.c 文件。對(duì) Makefile 做如下設(shè)置: 
PROGRAM   := hello      # 設(shè)置運(yùn)行程序名
SRCDIRS   := .          # 源程序位于當(dāng)前目錄下
SRCEXTS   := .c         # 源程序文件只有 .c 一種類

CFLAGS    := `pkg-config --cflags gtk+-2.0`  # CFLAGS
LDFLAGS   := `pkg-config --libs gtk+-2.0`    # LDFLAGS

這是一個(gè) C 程序,所以 CXXFLAGS 沒(méi)有必要設(shè)置——即使被設(shè)置了也不會(huì)被使用。 
編譯和連接 GTK+ 庫(kù)所需要的 CFLAGS 和 LDFLAGS 由 pkg-config 程序自動(dòng)產(chǎn)生。 
現(xiàn)在就可以運(yùn)行 make 命令編譯、./hello 執(zhí)行這個(gè) GTK+ 程序了。

 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多