[英]How do I run a C++ file “by itself” in a Visual Studio project without the influence of other files?
I'm EXTREMELY new to Visual Studio and C++ in general and I wanted to run a file within a project with other files in it.一般来说,我对 Visual Studio 和 C++ 非常陌生,我想在项目中运行一个包含其他文件的文件。 The file contains the simple code to print "Hello, World.", When I run this file.该文件包含打印“Hello, World.”的简单代码,当我运行该文件时。 an error claims that main() has been defined in a.obj file which contains simple addition code as well.一个错误声称 main() 已在包含简单添加代码的 a.obj 文件中定义。 These two files are in the same project.这两个文件在同一个项目中。
For some reason (maybe because of my ignorance) it seems nobody else has this problem.出于某种原因(也许是因为我的无知),似乎没有其他人有这个问题。
Here's the error:这是错误:
Error LNK2005 _main already defined in addition.obj
C++ can only have one main()
per program as the compiler says.正如编译器所说,C++ 每个程序只能有一个main()
。
You need Visual Studio to treat the files as separate programs.您需要 Visual Studio 将文件视为单独的程序。 To do that you need to create separate projects for each of the files and compile them separately.为此,您需要为每个文件创建单独的项目并单独编译它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.