Jump to content
  • Advertisement
Sign in to follow this  
sniffbaron

c++ unresolved external symbol help

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!