标题:一个程序两个以上源文件怎么编译呢?
只看楼主
peng880610
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:128
专家分:123
注 册:2017-3-29
结帖率:100%
已结贴  问题点数:17 回复次数:4 
一个程序两个以上源文件怎么编译呢?
<----------------------------------------------文件名:staticOutside.c---------------------------------------->
#include <stdio.h>
#include <conio.h>
static int num=10;
int main()
{
    printf("num in Outside.c is %d,address is %p\n",num,&num);
    void print1(void);
    void print2(void);
    print1();
    print2();
    getch();
    return 0;
}
<---------------------------------------------文件名:Func.c------------------------------------------------->
#include <stdio.h>
#include <conio.h>
static int num=100;
void print1()
{
    static int num=1000;
    printf("num in print1 is %d,address is %p\n",num,&num);
}

void print2()
{
    printf("num in print2 is %d,address is %p\n",num,&num);
}
上面这程序没发编译,求大神前辈帮忙解答下,
搜索更多相关主题的帖子: address include return 源文件 
2017-05-27 23:59
renkejun1942
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:不是这样
等 级:贵宾
威 望:33
帖 子:1645
专家分:5297
注 册:2016-12-1
得分:6 
一起编译。
IDE的话需要建立2个源文件。
类Gcc 编译器, 以下命令为例:gcc -Wall wenjian1.c wenjian2.c -o wenjian

09:30 05/21 种下琵琶种子,能种活么?等待中……
21:50 05/27 没有发芽。
20:51 05/28 没有发芽。
23:03 05/29 没有发芽。
23:30 06/09 我有预感,要发芽了。
2017-05-28 00:02
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
得分:6 
编译多个C文件链接还是有点麻烦的~可以用.h头文件编译比较方便~就是这样~~

[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2017-05-28 00:18
peng880610
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:128
专家分:123
注 册:2017-3-29
得分:0 
回复 2楼 renkejun1942
这样也不行,
2017-05-28 00:40
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:6 

<----------------------------------------------文件名:staticOutside.c---------------------------------------->
#include <stdio.h>
#include <conio.h>
static int num=10;
#include "Func.c"
int main()
{
    printf("num in Outside.c is %d,address is %p\n",num,&num);
    print1();
    print2();
    getch();
    return 0;
}

<---------------------------------------------文件名:Func.c------------------------------------------------->
#include <stdio.h>
#include <conio.h>
void print1()
{
    static int num=1000;
    printf("num in print1 is %d,address is %p\n",num,&num);
}

void print2()
{
    printf("num in print2 is %d,address is %p\n",num,&num);
}
2017-05-28 06:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-477430-1-1.html




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

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