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

test1.c

1
2
3
4
5
6
#include <stdio.h>
#include "test.h"
 
void test1(){
    printf(add1);
}

 test2.c

1
2
3
4
5
6
7
8
9
#include <stdio.h>
#include "test.h"
 
void test2(){
    printf(add2);
    for(; i > 0; i--){
        printf("%d-", i);
    }
}

 test.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
#include "test.h"
 
char add1[] = "www.shellbox.cn/n";<br><br>char add2[] = "www.scriptbox.cn/n";<br><br><br>int i = 10;
extern void test1();
extern void test2();
 
int main(){
    test1();
    printf("ok/n");
    test2();
    printf("%d/n", i);
    return 0;
}

 test.h

1
2
3
4
5
6
7
8
9
#ifndef _TEST_H_
#define _TEST_H_
 
extern char add1[];<br>extern char add2[];
extern int i;
void test1();
void test2();
 
#endif

 Makefile

1
2
3
4
5
6
7
8
9
10
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

posted on   Matrixin  阅读(798)  评论(0编辑  收藏  举报

努力加载评论中...

导航

点击右上角即可分享
微信分享提示