Chinaunix首页 | 论坛 | 博客
  • 博客访问: 917926
  • 博文数量: 84
  • 博客积分: 4334
  • 博客等级: 上校
  • 技术积分: 1610
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-27 07:49
文章分类

全部博文(84)

文章存档

2012年(5)

2011年(21)

2010年(58)

分类: Python/Ruby

2012-03-18 19:58:58

As you all known,there are four steps  for compiling:
(1)Pre-processing
(2)Compiling
(3)Assembling
(4)Linking

A typical example is:
hello.c-->pre-processing,hello.i-->compiling,hello.s-->Assembling,hello.o-->Linking,hello(execute)

OK,turn to gcc/g++ command!
-g:create debug info.
-c:only compile and create the target file.
-o FILE:create the file specified.
-I  DIRECTORY: include the additional header file path in DIRECTORY。
-L DIRECTORY: include the additional library path in DIRECTORY。

Now,there is a file named main.cpp, write a Makefile just as:

  1. #! /bin/sh

  2. #define the variables
  3. BIN = main
  4. OBJS += main.o
  5. SRC += main.cpp
  6. CC = g++
  7. CFLAGS = -g -o

  8. #define target and command
  9. #ld --> create the execute file
  10. $(BIN): $(OBJS)
  11.   $(CC) $(CFLAGS) $@ $^

  12. #compile --> create the (x).o file
  13. $(OBJS): $(SRC)
  14.   $(CC) -g -c $^

  15. clean:
  16.   rm *.o
What I get the most important point is that,pay attention to the  "=/+=" and ":",the former is defined for variables,but the latter expressed the dependency.

阅读(2872) | 评论(0) | 转发(0) |
0

上一篇:shell的if判断

下一篇:没有了

给主人留下些什么吧!~~