falconK
falconK

Reputation: 371

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.

Upvotes: 5

Views: 23984

Answers (4)

mwfearnley
mwfearnley

Reputation: 3669

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.

After renaming it I went into its properties, and changed the Item Type to <reset to default>, which reset it to C/C++ Compiler.

Upvotes: 0

falconK
falconK

Reputation: 371

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.

Upvotes: 6

Xearinox
Xearinox

Reputation: 3234

WinMain as entry point is missing.

Upvotes: 2

Adam Rosenfield
Adam Rosenfield

Reputation: 400592

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.

Upvotes: 3

Related Questions