Author Topic: error LNK2001: unresolved external symbol _WinMainCRTStartup  (Read 18583 times)

mutabor

  • Guest
error LNK2001: unresolved external symbol _WinMainCRTStartup
« on: January 19, 2008, 05:28:14 pm »
Hello,

Im a newbie in c++ AND Code::Blocks, so maybe someone can help me to solve the following problem:

Im using Microsoft Platform SDK and Microsoft Visual C++ Toolkit 2003.

I try to build a little WIN32GuiApplication (-Projekt), just for testing.
Here is my code:

********************************************

#include <windows.h>

int WINAPI main(HINSTANCE hInstance, 
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow) 
{

    MessageBox(0, "Nachricht", "Titel", MB_OK);

    return 0;
}

******************************************

When I try to compile the source, I get the following error message:

error LNK2001: unresolved external symbol _WinMainCRTStartup

I searched Google and I think it has something to do with the entry-point of the application (?).
So I think I have to change some Linker-Options or whatever ?!

Could someone please tell me, how to solve this problem and getting the source compiled?

Thank you, mutabor

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6484
    • My Best Post
Re: error LNK2001: unresolved external symbol _WinMainCRTStartup
« Reply #1 on: January 25, 2008, 09:02:20 am »
error LNK2001: unresolved external symbol _WinMainCRTStartup

This is an linker type error implies the idea that you are missing an needed library.

I suggest it might be the Library MSVCRT. I have no idea if that is the Library name or not.

What is your OS? XP, Vista, etc.

What version of the Platform SDK? Some of the new SDKs may have issues with 2003 Toolkit; I can not remember if that is so or not.

Tim S

« Last Edit: January 25, 2008, 09:33:10 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6484
    • My Best Post
Re: error LNK2001: unresolved external symbol _WinMainCRTStartup
« Reply #2 on: January 25, 2008, 09:35:56 am »
Try compiling in release and post your build log with full compiler logging on.

[full compiler logging]
Settings -> Compiler and Debugger -> Tab "Other" -> Compiler logging = "Full command line".

Tim S

Note: I installed an PSDK called PSDK-x86.exe dated 2005/2006; no idea where to download it from.

Google suggested it was this link I got it from
http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en

Code: [Select]
-------------- Build: Release in Test ---------------

cl.exe /nologo /W3  /Og /Ox /DNDEBUG    /I"C:\Program Files\Microsoft Platform SDK\include" /I"C:\Program Files\Microsoft Visual C++ Toolkit 2003\include"  /IF:\SourceCode\Projects\sokoban\ksokoban-svn\Test /c main.cpp /Foobj\Release\main.obj
main.cpp
link.exe /nologo /subsystem:windows /LIBPATH:"C:\Program Files\Microsoft Platform SDK\lib" /LIBPATH:"C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib"  /out:bin\Release\Test.exe gdi32.lib user32.lib kernel32.lib  obj\Release\main.obj   
Output size is 22.50 KB
« Last Edit: January 25, 2008, 09:41:42 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

mutabor

  • Guest
Re: error LNK2001: unresolved external symbol _WinMainCRTStartup
« Reply #3 on: January 25, 2008, 05:58:52 pm »
Hi Tim,

thank you for your replies!

I am using WindowsXP, Microsoft Platform SDK and Microsoft Visual C++ Toolkit 2003.

I searched for the msvcrt.lib in the Toolkit/Lib folder and only found it in an AMD64- and IA64-folder (!), so I think its the wrong (64-bit) version ?!

Do I have to get an other version of the msvcrt.lib or do I have to download the whole SDK again?
I admit, that I am a little bit confused :-(

Here is, what I get from Code:Blocks Build Log:

-------------- Build: default in Windows ---------------
link.exe /nologo /subsystem:windows /LIBPATH:"C:\Programme\Microsoft Visual C++ Toolkit 2003\lib"  /out:Windows.exe gdi32.lib user32.lib kernel32.lib  .objs\main.obj   
LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
Windows.exe : fatal error LNK1120: 1 unresolved externals
Process terminated with status 1 (0 minutes, 1 seconds)
2 errors, 0 warnings
 
Any help would be great!

Thanx, mutabor


« Last Edit: January 25, 2008, 06:02:14 pm by mutabor »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9488
Re: error LNK2001: unresolved external symbol _WinMainCRTStartup
« Reply #4 on: January 25, 2008, 08:33:18 pm »
-------------- Build: default in Windows ---------------
LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
...mind using Google before asking? ;-)
http://www.google.de/search?q=unresolved+external+symbol+_WinMainCRTStartup
Note that compiler errors are an issue of the *compiler*. We can't know all compiler in detail. So when such things happen - use Google and/or contact the compiler devs.
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6484
    • My Best Post
Re: error LNK2001: unresolved external symbol _WinMainCRTStartup
« Reply #5 on: January 26, 2008, 06:41:25 am »
You are missing the Linker search Directory of $(#psdk.lib)

Steps to fix are

1. Create Global Variable psdk

a. "Settings" -> "Global Variables"
b. Look for psdk in "Current Variable" lookup/downdown list
c1. If there fix/verify value of "Base"
 Mine is C:\Program Files\Microsoft Platform SDK
c2. if not there Add
    i. Click on new on same line as "Current Variable"
   ii. Use  psdk as "New Variable" name
  iii. Set Base to proper path in my case it was
      C:\Program Files\Microsoft Platform SDK

2. Add Linker search Directory of $(#psdk.include)
 
a. "Project" -> "Build Options"
b. Select the project name the highest item in left window
c. Click on Tab "search directories"
d. verify/add $(#psdk.include) under "Compiler" Tab
e. verify/add $(#psdk.lib) under "Linker" tab


Note: My most resent PSDK did not work with Toolkit 2003, but I have no idea if that is your problem, what PSDK are you using? Needed if the above directions do not fix problems.

Note: I need to know if you are compiling release which defines NDEBUG or debug which defines _DEBUG if the above info does not fix problem.


Tim S
« Last Edit: January 26, 2008, 06:50:12 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6484
    • My Best Post
Re: error LNK2001: unresolved external symbol _WinMainCRTStartup
« Reply #6 on: January 26, 2008, 06:58:22 am »
Read, my prior post for what I think is the problem, below answers to some of your questions.
Tim S

I searched for the msvcrt.lib in the Toolkit/Lib folder and only found it in an AMD64- and IA64-folder (!), so I think its the wrong (64-bit) version ?!

I only found msvcrt.lib in the same places in the PSDK (MS Platform SDK), do not think that is reason to believe SDK bad.

Do I have to get an other version of the msvcrt.lib or do I have to download the whole SDK again?
I admit, that I am a little bit confused :-(

If you give me the url or version of your PSDK? I can try it, to see if it works OK, may take awhile to download took me about 2 hours to do the old PSDK I just did of PSDK-x86.exe it's a web install file of 1.3 megs so it just install the files that urls are inside the exe.

Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org