如何修复在 C++ 中已经定义的 -main? [英] How do I fix already defined -main in c++?

查看:93
本文介绍了如何修复在 C++ 中已经定义的 -main?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有编程方面的背景知识,只有在学校学习过一点 html 编码.我从 2 天前开始学习 C++,目前正在学习输入和输出流,甚至还不了解调试.我启动了一个 Visual Studio 项目并编写了第二个程序,简单的 hello world,就像第一个一样.但这一次发生了错误,_main 已经在第一个程序的 .obj 中定义.这是什么意思,有什么问题,我该如何应对并继续工作?错误 LNK2005 _main我查看了错误代码,什么也不懂,更不用说找出如何修复它了.请简单回答.提前致谢

I have no background knowledge about programming, only experience I have is a little html coding in school. I literally started 2 days ago learning c++ and currently learning input and output streams, don't even understand debugging yet. I started a Visual Studio Project and wrote a second program, simple hello world, just like in the first. But this time, error occurred, _main is already defined in the .obj of the first program. What does this mean, what is the problem, how can I counter it and keep on working? Error LNK2005 _main I looked up the error code and understood nothing let alone found out how to fix it. Easy answers please. Thanks in advance

程序:

#include "pch.h"
#include <iostream>

using namespace std;

int main() {
    cout << "Hello World2" << endl;
    return 0;
}

推荐答案

如果您的 Visual Studio 项目中有两个文件 (.cpp),每个文件都包含一个 main_tmain 函数,链接将失败,因为只能定义一个 main 函数.

If you have two files (.cpp) in your visual studio project each containing a main or _tmain function, link will fail because there can only be one main function defined.

重命名所有其他 main 函数,你会没事的.

Rename all other main function and you'll be fine.

这篇关于如何修复在 C++ 中已经定义的 -main?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆