几个函数源码如下:
[root@LinuxServer1 Test]# cat main.c
void printg1(void);
void printg2(void);
int main()
{
printg1();
printg2();
return 0;
}
[root@LinuxServer1 Test]# cat g1.c
#include <stdio.h>
int g1=1;
void printg1(void)
{
printf("In g1: %d/n", g1);
}
[root@LinuxServer1 Test]# cat g2.h
#include <stdio.h>
int g1;
[root@LinuxServer1 Test]# cat g2.c
#include "g2.h"
void printg2(void)
{
int g2 = g1;
printf("In g2: %d/n", g2);
}
执行编译命令gcc,正常通过:
[root
[root@LinuxServer1 Test]# cat main.c
void printg1(void);
void printg2(void);
int main()
{
printg1();
printg2();
return 0;
}
[root@LinuxServer1 Test]# cat g1.c
#include <stdio.h>
int g1=1;
void printg1(void)
{
printf("In g1: %d/n", g1);
}
[root@LinuxServer1 Test]# cat g2.h
#include <stdio.h>
int g1;
[root@LinuxServer1 Test]# cat g2.c
#include "g2.h"
void printg2(void)
{
int g2 = g1;
printf("In g2: %d/n", g2);
}
执行编译命令gcc,正常通过:
[root