3 回答
TA贡献1871条经验 获得超8个赞
你是说直接编译吗?VC++ 6.0 编译器:
CL Amain.c sub\file.c sub2\file2.c
就生成 Amain.exe 了。
例如:
主文件里有 原型声明 extern void hello(char *name);
有 调用 hello("abcd");
file.c 里有:
#include <stdio.h>
void hello(char *name)
{printf("hello %s !\n", name);}
跑 Amain.exe 就可以了。
TA贡献1827条经验 获得超7个赞
写个Makefile , 以下在msys下测过 没问题
/* base 下的 main.c */
#include <stdio.h>
#include "./sub/file.h" /* 注意 sub前面是 点和缸 */
int main()
{
printf("enter main function!\n");
hello("veket_linux");
printf("back to main!\n");
return 0;
}
/* base 下的 sub 下的 file.c */
#include <stdio.h>
extern void hello(char *name)
{
printf("this is hello function, hello %s !\n", name);
}
/* base 下的 sub 下的file.c的头文件 file.h */
extern void hello(char *);
#base 下的 Makefile
main:main.o file.o
gcc -o main main.o ./sub/file.o -I"./sub"
main.o:main.c
gcc -c main.c
file.o:./sub/file.c
cd ./sub && gcc -c file.c && cd ..
终端下 在base 目录敲make命令
make就会自动调用命令显示如下
gcc -c main.c
cd ./sub && gcc -c file.c && cd ..
gcc -o main main.o ./sub/file.o -I"./sub"
- 3 回答
- 0 关注
- 94 浏览
添加回答
举报