C++ 我收到错误“链接:错误 LNK2001:无法解析的外部符号 _WinMainCRTStartup”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10611472/
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
I'm getting the error "LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup"
提问by falconK
Please help. On Visual Studio 2008, I'm getting the following errors.
请帮忙。在 Visual Studio 2008 上,我收到以下错误。
============================================================
1>Microsoft (R) Windows Resource To Object Converter Version 9.00.30729.01
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>adding resource. type:ICON, name:1, language:0x0409, flags:0x1010, size:744
1>adding resource. type:ICON, name:2, language:0x0409, flags:0x1010, size:296
1>adding resource. type:GROUP_ICON, name:128, language:0x0409, flags:0x1030, size:34
1>adding resource. type:DIALOG, name:100, language:0x0409, flags:0x1030, size:374
1>adding resource. type:DIALOG, name:102, language:0x0409, flags:0x1030, size:784
1>adding resource. type:VERSION, name:1, language:0x0409, flags:0x30, size:928
1>adding resource. type:STRING, name:7, language:0x0409, flags:0x1030, size:68
1>LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
1>.\Release/DiskTest.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\WinIRDir\Utilities\DiskTest\Release\BuildLog.htm"
1>DiskTest - 2 error(s), 0 warning(s)
1>Build log was saved at "file://c:\WinIRDir\Utilities\CommApp\Release\BuildLog.htm"
==============================================================
Here is the situation. - DiskTest.exe is one of 3 projects in my solution - This project builds perfectly for Debug x64, Release x64, and Debug Win32. Release Win32 is the only one generating these errors. - I have spend hours comparing the properties pages for all 4 config/machine combinations, and am confident that no properties are missing from one version to the next. I paid special attention to "Additional dependencies", "Additional Librari Directories", "Input", etc. Ofcourse, paths to .lib files point to either \Debug or \Release, and \x86 or \x64 for the respective config or platform.
这是情况。- DiskTest.exe 是我的解决方案中的 3 个项目之一 - 该项目非常适合 Debug x64、Release x64 和 Debug Win32。发行版 Win32 是唯一产生这些错误的版本。- 我花了几个小时比较所有 4 种配置/机器组合的属性页面,并且我相信从一个版本到下一个版本都没有丢失任何属性。我特别注意“附加依赖项”、“附加库目录”、“输入”等。当然,.lib 文件的路径指向 \Debug 或 \Release,以及指向相应配置或平台的 \x86 或 \x64 .
The only "additional dependency" this project has is SBF_Util.lib and SBF_Utild.lib for Debug. I made sure that all 4 versions (debug win32 and x64, and Release win32 and x64) of this library exist in the folder specified in each "additional library directory" I also checked dumpbin on each version of the library to make sure the platform matches.
该项目唯一的“附加依赖项”是用于调试的 SBF_Util.lib 和 SBF_Utild.lib。我确保该库的所有 4 个版本(调试 win32 和 x64,以及发布 win32 和 x64)都存在于每个“附加库目录”中指定的文件夹中我还检查了每个版本的库上的 dumpbin 以确保平台匹配.
I have seen other situations where a main entry point is missing, but in this case, all other versions build with no problems, it is only on Win32 Relase version that generates this error, so I don't think I need to change anything in the code.
我见过缺少主要入口点的其他情况,但在这种情况下,所有其他版本都没有问题,只有在 Win32 Relase 版本上才会生成此错误,因此我认为我不需要更改任何内容编码。
Can anybody provide any clues?, I'm out of ideas. Any ideas will be very much appreciated. Thanks.
任何人都可以提供任何线索吗?,我没有想法。任何想法将不胜感激。谢谢。
回答by falconK
UNBELIEVABLE!!!
逆天!!!
I found the problem! It was an incredibly simple thing what was causing this criptic error: A "SPACE"
我发现了问题!导致这个严重错误的原因非常简单:“空格”
It turns out that under Configuration->C/C++->OutputFiles->Object File Name: I had: "$(IntDir)\ "
原来在 Configuration->C/C++->OutputFiles->Object File Name: I had: "$(IntDir)\ "下
Didn't notice the space until I paid very close attention to the Kdiff3 window, and noticed this tiny underscore to signal a space.
This space had been there for months, as this project had been left unattended (before I came on board), because nobody could find the fix for it, so they just stopped using it.
Most likely a copy-paste error.
直到我非常密切地注意 Kdiff3 窗口并注意到这个微小的下划线来表示空格时才注意到空格。
这个空间已经存在好几个月了,因为这个项目一直无人看管(在我加入之前),因为没有人能找到修复它的方法,所以他们只是停止使用它。很可能是复制粘贴错误。
Thank you all guys for your ideas. Specially the first answer from Xearinox that made me think about comparing all modes. I'll try to find some time to write a tool to parse the project/solution files into a 4-column sheet that lists all properties for all configurations and platforms, so we can easily compare them. Thank you all again.
谢谢大家的想法。特别是 Xearinox 的第一个答案让我考虑比较所有模式。我会尝试找一些时间来编写一个工具来将项目/解决方案文件解析为一个 4 列的表格,其中列出了所有配置和平台的所有属性,以便我们可以轻松地比较它们。再次感谢大家。
回答by Adam Rosenfield
Open up your project's settings page, go to Linker→ Systemand examine the SubSystemproperty. Make sure it's set to the same value in all project configurations by switching the configuration from the configuration drop-down box.
打开项目的设置页面,转到链接器→系统并检查子系统属性。通过从配置下拉框中切换配置,确保在所有项目配置中将其设置为相同的值。
Assuming that your intended entry point is main
(or one of its variants such as _tmain
or wmain
), you want to make sure to use the SubSystem property is set to CONSOLE.
假设您的预期入口点是main
(或其变体之一,例如_tmain
或wmain
),您要确保将 SubSystem 属性设置为CONSOLE。
回答by Xearinox
WinMain as entry point is missing.
缺少 WinMain 作为入口点。
回答by mwfearnley
In my case, the file I was trying to compile had the wrong properties.
就我而言,我试图编译的文件具有错误的属性。
I had created the file with a stray character in the file extension, and so my project gave it the wrong Item Type: Does not participate in build
.
我在文件扩展名中创建了一个带有杂散字符的文件,所以我的项目给了它错误的项目类型:Does not participate in build
。
After renaming it I went into its properties, and changed the Item Type to <reset to default>
, which reset it to C/C++ Compiler
.
重命名后,我进入了它的属性,并将项目类型更改为<reset to default>
,将其重置为C/C++ Compiler
.