Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm getting the error "LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup"

Please help. On Visual Studio 2008, I'm getting the following errors.

============================================================

   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.

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.

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.

Can anybody provide any clues?, I'm out of ideas. Any ideas will be very much appreciated. Thanks.

like image 546
falconK Avatar asked May 16 '12 03:05

falconK


People also ask

How do I fix unresolved external symbol LNK2001?

To fix this issue, add the /NOENTRY option to the link command. This error can occur if you use incorrect /SUBSYSTEM or /ENTRY settings in your project. For example, if you write a console application and specify /SUBSYSTEM:WINDOWS, an unresolved external error is generated for WinMain .

What causes unresolved external symbol?

The compiler can identify when a symbol isn't declared, but it can't tell when the symbol isn't defined. It's because the definition may be in a different source file or library. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error.

What does unresolved external symbol mean?

Unresolved external references occur when the symbol for a function or global variable is referenced in a program, but none of the object files or libraries specified in the link step contain a definition for that symbol.

What kind of error is unresolved external symbol?

Error LNK2001: unresolved external symbol _main An unresolved external occurs when some code has a call to a function in another module and the linker can't find that function in any of the modules or libraries that you are currently linking to.


3 Answers

WinMain as entry point is missing.

like image 26
Xearinox Avatar answered Sep 28 '22 11:09

Xearinox


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)\ "

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.

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.

like image 139
falconK Avatar answered Sep 28 '22 10:09

falconK


Open up your project's settings page, go to LinkerSystem and examine the SubSystem property. 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.

like image 23
Adam Rosenfield Avatar answered Sep 28 '22 10:09

Adam Rosenfield