终端下编译运行一个简单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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步