简体   繁体   English

如何在 Visual Studio 项目中“单独”运行 C++ 文件而不受其他文件的影响?

[英]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.

相关问题 Visual Studio C ++项目管理。 如何处理项目中的非代码文件? - Visual Studio C++ project management. How do I handle non-code files in a project? 如何从其他C ++项目中构建和运行Visual Studio-8中的C ++项目? - How a C++ project in visual studio-8 can be build and run from other C++ project? 如何在 Visual Studio 中编辑 c++ 项目的源文件? - How do I edit the source files of a c++ project in Visual Studio? 如何从 Visual Studio 项目中读取 C++ 中的 netcdf 文件? - How do i read netcdf files in c++ from a visual studio project? 源文件 header 文件和其他文件在 Visual Studio 2019 中创建空 C++ 项目时不显示 - Source file header file and other files are not displayed when I create empty C++ Project in visual studio 2019 如何在 Visual Studio 中打开 C++ 项目文件夹? - How do I open a c++ project folder in visual studio? 如何将扩展链接到Project(Visual Studio C ++) - How do I link Extensions to Project (Visual Studio C++ ) 如何在Visual Studio C ++项目中找到iostream头文件? - How do I find the iostream header file in a Visual Studio C++ project? C++ 从 visual studio 项目中的所有文件运行一个 cpp 文件 - C++ run one cpp file from all files in visual studio project 如何使Visual Studio 2015 C ++项目与Visual Studio 2010兼容? - How do I make a Visual Studio 2015 C++ project compatible with Visual Studio 2010?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM