Visual C++ 2010 - 致命错误 LNK1169:发现一个或多个多重定义的符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6506367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual C++ 2010 - fatal error LNK1169: one or more multiply defined symbols found
提问by Suhail Gupta
this is a program :
这是一个程序:
#include <iostream>
using namespace std;
int main() {
cout << "Enter a number";
int i;
cin >> i;
try {
if( i == 0 ) throw 0;
if( i == 2 ) throw "error";
} catch( int i ) {
cout << "can't divide by 0";
}
catch( ... ) {
cout << "catching other exceptions";
}
}
On compiling (Microsoft visual C++ 2010 express on Windows 7), I get the error which says:
在编译(Windows 7 上的 Microsoft Visual C++ 2010 express)时,我收到错误消息:
fatal error LNK1169: one or more multiply defined symbols found
致命错误 LNK1169:找到一个或多个多重定义的符号
回答by saplingPro
Actually there is no error in this code.
实际上这段代码没有错误。
Number of source files could be the problem.
Try this code as a new project in the same compiler or try deleting the files from the source files
option in the left side of Text Area (i.e where you are writing your code)
源文件的数量可能是问题所在。将此代码作为同一编译器中的新项目尝试或尝试从source files
文本区域左侧的选项中删除文件(即您编写代码的位置)
This should compile then.
这应该编译。
回答by saqrthabet
Finally I think that I found the most plausible explanation for the problem as you know we usually assign main as an integer (int main) in our .cpp file and sometimes we may write more than one .cpp file in the same project with the same (int main () ).so for the program that means we have accidentally repeated the same function twice in the same project folder .What we have to do is this just write one .cpp file with (int main) while the other .cpp files in the same project write them with (int submain) and see what gona happen.
最后我想我找到了对这个问题最合理的解释,因为你知道我们通常在我们的 .cpp 文件中将 main 分配为一个整数(int main),有时我们可能会在同一个项目中用相同的方式编写多个 .cpp 文件(int main () ).so 对于程序,这意味着我们不小心在同一个项目文件夹中重复了相同的函数两次。我们要做的就是用 (int main) 编写一个 .cpp 文件,而另一个 .cpp同一个项目中的文件用 (int submain) 写它们,看看会发生什么。
回答by xxochiexx
try to change your int main()
to int submain()
.
尝试将您的更改int main()
为int submain()
.
回答by Raveline
I suspect your error come from this line :
我怀疑你的错误来自这一行:
catch(int i)
You've already got a variable named like that in this range. Also, you should catch exceptions, not integer.
你已经在这个范围内得到了一个这样命名的变量。此外,您应该捕获异常,而不是整数。