| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 297 人关注过本帖
标题:请问用gcc怎么进行多文件编译?
只看楼主 加入收藏
ilsoviet1917
Rank: 2
等 级:论坛游民
帖 子:103
专家分:26
注 册:2010-5-11
结帖率:84.21%
收藏
已结贴  问题点数:20 回复次数:2 
请问用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下多文件编译是这么写吗?还是代码有问题?
2015-11-26 09:53
hellovfp
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:禁止访问
威 望:30
帖 子:2976
专家分:7697
注 册:2009-7-21
收藏
得分:20 
partb.c

void accumulate (int k)-->>extern void accumulate (int k);

我们都在路上。。。。。
2015-11-26 10:39
八画小子
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:37
帖 子:709
专家分:2063
注 册:2010-11-11
收藏
得分:0 
gcc parta.c -c parta.o
gcc partb.c -c partb.o
ld parta.o partb.o -o part

这是linux下的编译命令,win下的一样。不过,扩展名可能需要相应地改一下。
2015-11-26 19:37
快速回复:请问用gcc怎么进行多文件编译?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015208 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved