Public Group

# c++ unresolved external symbol help

This topic is 2873 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I am trying to learn myself c++, but I have run into some issues. When I try to compile a program in visual c++ express I get the error

1>------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------
1>LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
1>c:\users\jonas\documents\visual studio 2010\Projects\HelloWorld\Debug\HelloWorld.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Hope sombody have some ideas of what to do

##### Share on other sites
Does your program use a main() function? If so, it sounds like when you created the project you created a Windows project rather than a console project. Go to your linker settings and change the subsystem from Windows to console.

##### Share on other sites
If you want to write a console application (like a command prompt interface), then you should create a Visual Studio project with the Win32 Console Application template.
I think this should work for you.

EDIT: SiCrane beat me to it

##### Share on other sites
Hi again. I reading the book "Beginning game programming" by Jonathan S. Harbour, and I just followed the instructions of the book. It is supposed to be a win32 project and it worked for the author.

here is the code

 // Beginning Game Programming, Third Edition // Chapter 1 - HelloWorld program #include <windows.h> int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { MessageBox(NULL, "Motoko Kusanagi has hacked your system!", "Public Security Section 9", MB_OK | MB_ICONEXCLAMATION); } 

##### Share on other sites

Hi again. I reading the book "Beginning game programming" by Jonathan S. Harbour, and I just followed the instructions of the book. It is supposed to be a win32 project and it worked for the author.

here is the code

 // Beginning Game Programming, Third Edition // Chapter 1 - HelloWorld program #include <windows.h> int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { MessageBox(NULL, "Motoko Kusanagi has hacked your system!", "Public Security Section 9", MB_OK | MB_ICONEXCLAMATION); } 

Your probably need to tell your compiler where to search for windows.h.

##### Share on other sites
Not trying to be condescending here, but if you don't know what that error means in the given context, and that book has not explained to you how to set this project up properly (by telling the compiler where to find the proper library as was mentioned before) then that book is probably not for absolute beginners. I would recommend getting a book about C++, or using some online tutorials (there are a ton of them) to learn C++ before you dive into windows or game programming.

##### Share on other sites
Hi again. The book did tell me how to set up the project, and I do infact have a basic understanding of c++
I'll double check that i'v done everything right (again) and see if I can get it working.
It may be because the examples of the book are for the 2008 version of visual c++, while I have the 2010 version.
Would this be an issue?

##### Share on other sites
i run into this problem A LOT. (every project) and there's a bit of troubleshooting i do to fix it. try renaming your WinMain function to _tWinMain.
if that doesn't work, in the project properties -> Linker -> Advanced, set the property "Entry Point" to WinMain. (if you have to use this method, beware: it may not allocate memory to any global variables)

##### Share on other sites
Im pretty sure he just forgot to add the .cpp file in the project (Solution Explorer->Source), since the output dosen't show "compiling helloworld.cpp or whatever). I don't know what you mean by "Your probably need to tell your compiler where to search for windows.h."... this file should be in the paths of the compiler by default, there's nothing to setup to use it(unless you change the folder location which would be stupid). Never had in my 10 years of programming the need to change WinMain to _tWinMain or set up the entry point by hand either...
That code should work on every vc version. Also make sure you created a win32 application and not a console application.

##### Share on other sites
Thx alot, now it works perfectly :-)

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 21
• 23
• 11
• 25