请问用gcc怎么进行多文件编译?
按照书上的例题写了两段代码parta.c
程序代码:
#include <stdio.h> void report_count (); void accumulate (int k); int count = 0; int main (void) { int value; register int i; printf ("Enter a positive integer (0 to quit):"); while (scanf ("%d", &value) == 1 && value > 0) { ++count; for (i = value; i >= 0; i--) { accumulate (i); } printf ("Enter a positive integer (0 to quit):"); } report_count (); system ("pause"); return 0; } void report_count () { printf ("Loop executed %d times\n", count); }
partb.c
程序代码:
#include <stdio.h> extern int count; static int total = 0; void accumulate (int k) void accumulate (int k) { static int subtotal = 0; if (k <= 0) { printf ("loop cycle: %d\n", count); printf ("subtotal: %d; total: %d\n", subtotal, total); subtotal = 0; } else { subtotal += k; total += k; } }
然后用gcc 12_parta.c 12_partb.c -o 12_part.exe编译,出现以下错误提示
12_partb.c: In function 'accumulate':
12_partb.c:7:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
{
^
12_partb.c:21:1: error: expected '{' at end of input
}
^
gcc下多文件编译是这么写吗?还是代码有问题?