首页 > 编程语言 > 详细

终端下编译运行一个简单C++程序流程

时间:2015-06-29 13:01:28      阅读:293      评论:0      收藏:0      [点我收藏+]

test1.c

#include <stdio.h>
#include "test.h"

void test1(){
    printf(add1);
}

 test2.c

#include <stdio.h>
#include "test.h"

void test2(){
    printf(add2);
    for(; i > 0; i--){
        printf("%d-", i);
    }
}

 test.c

#include <stdio.h>
#include "test.h"

char add1[] = "www.shellbox.cn/n";

char add2[] = "www.scriptbox.cn/n";


int i = 10; extern void test1(); extern void test2(); int main(){ test1(); printf("ok/n"); test2(); printf("%d/n", i); return 0; }

 test.h

#ifndef _TEST_H_
#define _TEST_H_

extern char add1[];
extern char add2[]; extern int i; void test1(); void test2(); #endif

 Makefile

test: test.o test1.o test2.o
    gcc -o test test.o test1.o test2.o
test1.o: test1.c
    gcc -c -o test1.o test1.c
test2.o: test2.c
    gcc -c -o test2.o test2.c
test.o: test.c
    gcc -c -o test.o test.c
clean:
    rm test test.o test1.o test2.o

 执行:

make test

  运行:

./test

终端下编译运行一个简单C++程序流程

原文:http://www.cnblogs.com/fordreamxin/p/4607165.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!