本站首页   业内资讯   前沿下载  网络导航   本站论坛  
系统之家
设为首页
加入收藏
关于我们
IT业界  软件应用  电脑硬件  数码资讯  苹果MAC  Unix/Linux  系统优化  Web技术  认证考试  安全相关  游戏业界  Win2008  
首页 > Unix/Linux
 

 

新手学堂:Linux下Makefile文件简单概念
作者: 发布时间:2008-05-19 08:26:25 来源:
 

将各个模块的关系写进makefile,并且写明了编译命令,这样,当有模块的源代码进行修改后,就可以通过使用make命令运行makefile文件就可以进行涉及模块修改的所有模块的重新编译,其他模块就不用管了。

makefile文件的写法:

目标, 组件

规则

例如 有下面5个文件:

/* main.c */

#include "mytool1.h"

#include "mytool2.h"

int main(int argc,char **argv)

{

mytool1_print("hello");

mytool2_print("hello");

}

/* mytool1.h */

#ifndef _MYTOOL_1_H

#define _MYTOOL_1_H

void mytool1_print(char *print_str);

#endif

/* mytool1.c */

#include "mytool1.h"

void mytool1_print(char *print_str)

{

printf("This is mytool1 print %s/n",print_str);

}

/* mytool2.h */

#ifndef _MYTOOL_2_H

#define _MYTOOL_2_H

void mytool2_print(char *print_str);

#endif

/* mytool2.c */

#include "mytool2.h"

void mytool2_print(char *print_str)

{

printf("This is mytool2 print %s/n",print_str);

}

可以这样进行编译以便运行main这个可执行文件

gcc -c main.c (生成main.o)

gcc -c mytool1.c (生成mytool1.0)

gcc -c mytool2.c (生成mytool2.0)

gcc -o main main.o mytool1.o mytool2.o (生成main)

也可以这样写makefile文件

main main.o mytool.o mytool2.o

gcc -0 $@ $^

main.0 main.c mytool1.h mytool2.h

gcc -c $<

mytool1.0 mytool1.c mytool1.h

gcc -c $<(或者是mytool.c)

mytool2.0 mytool2.c mytool2.h

gcc -c $<(或者是mytool2.c)

通过make命令可以运行该文件,也就是进行编译了。

linux上有很多库,c语言编写的各种库的总称为libc,glibc为libc的一个子集,由gnu提供,内核提供的系统函数和系统调用是不包括在libc中。

linux系统默认会安装glibc

glibc中

常用库gcc会自动去查找,不予理会。

在/lib, /usr/lib, /usr/local/lib 在这三个路径下面有一些标准库,只需-l+库名 可以不必要指定路径。其他库必须在用gcc时用-L+具体的路径。


 
   
※ 相关信息
 ·新手学堂:Linux下载工具wget和a  (2008-05-17)
 ·新手学堂:Linux下kdevelop使用S  (2008-05-16)
 ·新手学堂:Linux操作系统中如何编  (2008-05-16)
 ·新手学堂:sys-unconfig命令的执  (2008-05-13)
 ·新手学堂:Linux系统下设置时钟简  (2008-05-09)
 ·新手学堂:Linux和Windows系统区  (2008-05-09)
 ·新手学堂:Linux操作下查看进程相  (2008-05-07)
 ·新手学堂:Linux limits.conf解释  (2008-05-03)
 ·新手学堂:Linux操作系统下如何添  (2008-05-03)
 ·新手学堂:Linux系统下网卡网络配  (2008-04-22)

   
   
 
 站内搜索
 
 网站最新
 
 人气排行 
 
 阿里妈妈

网站留言关于我们广告业务注册登录合作伙伴网站地图
Xtzj.Com 版权所有 辽ICP备05013013号
Copyright © 2008 All rights reserved