Makefile + SourceInsight的开发模式初探

前言

之前对于这种开发模式,知道的并不多;但是后来到了公司之后发现再也见不到windows下那么傻瓜式的IDE了。目前,公司采用的samba+sourceinsight+linux云服务器。
1. samba主要是提供了linux和windows的文件共享;
2. SI主要用来看代码和写代码;
3. linux云则主要是用来交叉编译的。
这样整个开发流程就非常清楚了,非常适合感兴趣的同学对其中细节进行探索。本文就对其中的开发模式进行初步的搭建:主系统windows7+VirtualBox+ubuntu虚拟机;
ok 开干!

准备

1.系统自己装吧
2.安装Oracle VM VirtualBox,该软件免费;自己来吧~
3.到官网下载ubuntu镜像,将其导入VirtualBox中;自己来 哈哈~

实战

首先在SI里创建源文件和头文件,为了示例本文就写几个简单的函数了,大家可以举一反三:
注意:在此之前一定要设置一下,主机和虚拟机的共享文件夹(具体的实现方法可以自行搜索);这样你才能在windows下面编辑,并把修改的代码同步的保存到了虚拟机当中。
测试文件:
1.main.c

/**
 * function:the demo for the Makefile
 * describe:just demo
 * author:LaMar
 */

#include "hello.h"

int main()
{
    int iVal = 666;

    printf("MyVal is %d", iVal);
    printHello();

    return 0;
}

2.hello.c

/**
 * function:the demo for the Makefile
 * describe:just demo
 * author:LaMar
 */

#include "hello.h"

void printHello()
{
    char *cHello = "this is my first for Makefile...";

    printf("\nHello everyone\n");
    printf("%s\t\n", cHello);

}

3.hello.h

/**
 * function:the demo for the Makefile
 * describe:just demo
 * author:LaMar
 */

#ifndef __HELLO_H__
#define __HELLO_H__

#include<stdio.h>

void printHello(void);

#endif

好了,最后主角登场了(初学,请大牛们清喷~~)
Makefile

#
# just for the demo Makefile
#

BASE_DIR = $(shell pwd)
OBJ = main.o hello.o

.PHONY:all clean

all:demo
    mv *.o $(BASE_DIR)/obj
    mv demo $(BASE_DIR)/app
    @echo "compile finished..."

demo:$(OBJ)
    cc -o demo $(OBJ)

main.o:main.c
    cc -c $< -o $@

hello.o:hello.c hello.h
    cc -c $< -o $@

clean:
    rm $(BASE_DIR)/app/* $(BASE_DIR)/obj/*

测试结果

1.建立共享文件夹之后,我们可以看到windows下的东西和虚拟机下的东西一模一样:
Windows下的文件
然后是虚拟机的:
ubuntu下的文件

2.之后就是在当前目录下执行:make,一步到位把可执行文件和编译中间生成的.o文件分门别类的存放;最后,执行可执行文件,如我们所预期的那样,可以正常的运行程序。

参考资料(致敬前辈):
1. GNU+makefile中文手册
2. 跟我一起写 Makefile


WeChat:flappy_two 欢迎交流~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值