Chinaunix首页 | 论坛 | 博客

tyz

  • 博客访问: 27994
  • 博文数量: 9
  • 博客积分: 1505
  • 博客等级: 上尉
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-22 16:57
文章分类
文章存档

2008年(9)

我的朋友
最近访客

分类:

2008-04-29 19:30:17

 
最近看了看Linux的make,终于使自己从gcc转到Makefile了
为什么使用Makefile呢?
我的理解就是如果你只有一个单个的C文件,你大可简单的gcc一下,但是如果你写了一堆.h,.c那该怎么办呢,怎么才能给它编译了呢,答案就是编写使用Makefile吧
注:Makefile和待编译的文件在一个目录下
一种最基本的Makefile的格式:

=== makefile 开始 ===

编译后可执行的文件名:依赖的obj文件列表

gcc 依赖的obj文件列表 -o 编译后可执行的文件名

obj文件:依赖的.o,.c文件的列表

gcc -c 文件名.c -o obj文件名.o

clean:

rm -rf 要删除的列表,一般写为*.o  可执行的文件名

=== makefile 结束 ===

=== makefile 开始 ===
helloworld:file1.o file2.o
gcc file1.o file2.o -o helloworld
file1.o:file1.c file2.h
gcc -c file1.c -o file1.o

file2.o:file2.c file2.h

gcc -c file2.c -o file2.o

clean:

rm -rf *.o helloworld

 === makefile 结束 ===

其中参考的文件为:

file1.c:
              #include
              #include "file2.h"
              int main()
              {
                     printf("print file1$$$$$$$$$$$$$$$$$$$$$$$$\n");
                     File2Print();
                     return 0;
              }

       file2.h:

              #ifndef FILE2_H_
              #define    FILE2_H_

                      #ifdef __cplusplus

                            extern "C" {

                     #endif

                     void File2Print();

                     #ifdef __cplusplus

                            }

                     #endif

              #endif

       file2.c:
              #include "file2.h"
              void File2Print()
              {
                     printf("Print file2**********************\n");
              }

注:这种最基本的格式基本的文件都可以搞定,稍有难度的可以参考

http://goodcandle.cnblogs.com/archive/2006/03/30/278702.html

 

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

上一篇:没有了

下一篇:正则表达式的学习

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