C++ 错误 LNK1561:必须定义入口点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17228301/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 21:01:36  来源:igfitidea点击:

Error LNK1561: entry point must be defined

c++cvisual-studio-2010linker-errors

提问by Euler

I am working with Visual Studio 2012.

我正在使用 Visual Studio 2012。

My Solution has 3 projects

我的解决方案有 3 个项目

projectA

项目A

projectB

项目B

projectC

项目C

and the Hierarchy is like

层次结构就像

projectCdepends on projectBwhich in turn depend on projectA. There is a main functionin projectC and no main in projectB and projectA. The errors that i am getting are:

projectC依赖于projectB而后者又依赖于projectA。projectC中有main函数,projectB和projectA没有main函数。我得到的错误是:

error LNK1561: entry point must be defined      projectA
error LNK1561: entry point must be defined      projectB

I have tried changing in the Configuration Properties -> Linker -> System -> SubSystem to Console (/SUBSYSTEM:CONSOLE) But the problem still persists

我尝试在配置属性 -> 链接器 -> 系统 -> 子系统到控制台(/SUBSYSTEM:CONSOLE)中进行更改但问题仍然存在

Help me out of this.

帮我解决这个问题。

回答by Spook

It seems, that you misunderstand the term "module". There is no such C++ project in Visual Studio; C++ projects may be divided into three categories:

看来,您误解了“模块”一词。Visual Studio 中没有这样的 C++ 项目;C++项目可以分为三类:

  • Programs - compilation produces an exefile, which may be executed;
  • Static libraries - compilation produces a libfile, which may be included in another project and are linked during the compilation;
  • Dynamic libraries - compilation produces a dllfile, which may be attached to your program at run-time and provide additional functionality.
  • 程序 - 编译产生一个exe文件,该文件可以被执行;
  • 静态库 - 编译生成一个lib文件,该文件可能包含在另一个项目中并在编译期间链接;
  • 动态库 - 编译生成一个dll文件,该文件可以在运行时附加到您的程序并提供附加功能。

From your description, you want the projectB and projectC to be a static libraries, but instead you created them as executable files. Run the new project wizard again and choose "static library" instead of "Windows application".

根据您的描述,您希望 projectB 和 projectC 成为静态库,但您将它们创建为可执行文件。再次运行新项目向导并选择“静态库”而不是“Windows 应用程序”。

You can read more about static libraries in the MSDN library.

您可以在MSDN 库中阅读有关静态库的更多信息。

If static libraries are too heavyweight for your application, you may simply include projectB and projectC files in your project (optionally take care of namespaces not to confuse the names of classes). It all depends on how much functionality you plan to implement in these "modules".

如果静态库对于您的应用程序来说太重了,您可以简单地在您的项目中包含 projectB 和 projectC 文件(可以选择注意命名空间,以免混淆类的名称)。这完全取决于您计划在这些“模块”中实现多少功能。

回答by user2852297

set Properties -> Linker -> System -> SubSystem to "Windows (/SUBSYSTEM:WINDOWS)"

将属性 -> 链接器 -> 系统 -> 子系统设置为“Windows (/SUBSYSTEM:WINDOWS)”

回答by Mark Aven

What's happening possibly, what was happening with me, is that when you switch your properties of your project to .dll from .exe, if you switch from debug to release or from x86 to x64, each time you do that it's switching you back to .exe. Each configuration has it's own properties.

可能发生的事情,发生在我身上的事情是,当您将项目的属性从 .exe 切换到 .dll 时,如果您从调试切换到发布或从 x86 切换到 x64,每次这样做都会将您切换回。可执行程序。每个配置都有它自己的属性。

So, go to Properties > Configuration Type > .dll

因此,转到“属性”>“配置类型”>“.dll”

If indeed you want to make a .dll.

如果你确实想制作一个.dll。

回答by One Ace

I'm going to guess you're using Windows for creating this project, for me, if I usually use SDL I get this error, all you have to do is type in this #include <Windows.h>that should fix it, if not then I'm not to sure how to fix that.

我猜你正在使用 Windows 来创建这个项目,对我来说,如果我通常使用 SDL 我会收到这个错误,你所要做的就是输入这个#include <Windows.h>应该修复它,如果不是那么我不是确定如何解决这个问题。