error LNK2005怎么解决 10
#include<stdio.h>#include"b.cpp"#include"c.cpp"voidmain(){intx,y,z;printf("Inputxandy...
#include <stdio.h>
#include "b.cpp"
#include "c.cpp"
void main()
{
int x,y,z;
printf("Input x and y:");
scanf("%d%d",&x,&y);
printf("%d\n",z=f1(x,y));
printf("%d\n",f2(x,y,z));
}
int f1(int m,int n)
{
int a,b,c;
if (m<n)
c=m,m=n,n=c;
a=m;
b=n;
while(b!=0)
{
c=a%b;
a=b;
b=c;
}
return a;
}
int f2(int s,int t,int r)
{
return s*t/r;
}
每次编译连接都会出现 b.obj : error LNK2005: "int __cdecl f1(int,int)" (?f1@@YAHHH@Z) already defined in a.obj
c.obj : error LNK2005: "int __cdecl f2(int,int,int)" (?f2@@YAHHHH@Z) already defined in a.obj
Debug/zc002.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
zc002.exe - 3 error(s), 0 warning(s)
请高手帮忙。
注:以上三个文件分别是a.cpp b.cpp c.cpp
本人自己已解决此问题,就是将#include "b.cpp" #include "c.cpp"
调换成#include "c.cpp" #include "b.cpp"
但是我不知道这是什么道理。求解 展开
#include "b.cpp"
#include "c.cpp"
void main()
{
int x,y,z;
printf("Input x and y:");
scanf("%d%d",&x,&y);
printf("%d\n",z=f1(x,y));
printf("%d\n",f2(x,y,z));
}
int f1(int m,int n)
{
int a,b,c;
if (m<n)
c=m,m=n,n=c;
a=m;
b=n;
while(b!=0)
{
c=a%b;
a=b;
b=c;
}
return a;
}
int f2(int s,int t,int r)
{
return s*t/r;
}
每次编译连接都会出现 b.obj : error LNK2005: "int __cdecl f1(int,int)" (?f1@@YAHHH@Z) already defined in a.obj
c.obj : error LNK2005: "int __cdecl f2(int,int,int)" (?f2@@YAHHHH@Z) already defined in a.obj
Debug/zc002.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
zc002.exe - 3 error(s), 0 warning(s)
请高手帮忙。
注:以上三个文件分别是a.cpp b.cpp c.cpp
本人自己已解决此问题,就是将#include "b.cpp" #include "c.cpp"
调换成#include "c.cpp" #include "b.cpp"
但是我不知道这是什么道理。求解 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询