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

相关文章:

  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2021-10-17
  • 2021-09-11
猜你喜欢
  • 2021-06-13
  • 2022-12-23
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2021-05-19
相关资源
相似解决方案