第六节 标准工程建立方法

以下,将介绍如何搭建工程。

1.文件分析,在Linux开发中,工程所建的文件类型主要有

.h  头文件
.c  源文件
.so 动态库
.a  静态库


2.文件放置(由于目前的开发还没用到库,为了防止误导,省略涉及.so以及.a文件。)

    inc/
    .h 文件
    src/
    .c 文件


3.各文件内容编写   

    main.c  如果工程规模不大(#include时小于2个自定义头文件),则可以不新建main.h,直接包含外部头文件即可。
    即预处理 + 外部函数声明 + 主函数(包括错误处理)

    #include <stdio.h> //常用头文件
    #include <head1.h>
    #include <head2.h>


    int main((int argc, const char *argv[])
    {
        function_from_head1();
        ...

        return 0;
    err:perror("The description about the reason caused the fault.");   
        return -1;
    }


    main.h  如果工程规模较大(#include时大于等于2个自定义头文件),则将main.c的预处理语句放置到main.h中,并在main.c中包含外部头文件
    即预处理语句(main.h)  

    #ifndef _MAIN_H_
    #define  _MAIN_H_

    #include <stdio.h>
    #inlucde <head1.h>
    ...
    #inlcude <headn.h>
    ...
    #endif

    包含头文件(main.c)

    #include <main.h>
    ...

    head.h
    条件宏定义,函数声明语句,所引用的头文件
    即

    #ifndef _HEAD1_H_
    #define _HEAD1_H_

    typedef XXX(变量类型) returntpye;

    returntype function1_from_head1();
    ...
    returntype functionn_from_head1();

    head.c
    函数主体,函数注释,函数外部接口等,预处理语句

4.编译输出
    一般大工程我们使用makefile(暂时略),但是小工程可以直接使用shell命令
    即arm-linux-gcc *.c -o #OutPutName -I #HeadFilePathName
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值