Solved

Build a Program

Posted on 1998-08-15
11
218 Views
Last Modified: 2010-04-01
I'm now learning Visual C++

Here is my first program:

#include <afxwin.h>

class HelloApp : public CWinApp
{
public:
      HelloApp ()
            : CWinApp ( "Hello World!" )
      {}

      BOOL InitInstance()
      {
            CFrameWnd *MyFrame = new CFrameWnd();
            m_pMainWnd = MyFrame;
            MyFrame->Create ( NULL, (LPCTSTR)"Hello World!" );
            MyFrame->ShowWindow (SW_SHOW );
            return TRUE;
      }
} HelloWorld;


When I try to build a .exe file, it gave me the following message:

--------------------Configuration: Dailup - Win32 Debug--------------------
Linking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
libcd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Dailup.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

Dailup.exe - 4 error(s), 0 warning(s)

what's wrong?
0
Comment
Question by:gen_genesis
  • 2
  • 2
  • 2
  • +5
11 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1170376
It sounds like you aren't linking to the MFC libraries.  But that should take place automatically in an MFC project.  Dod you create the project as an MFC application project?
0
 
LVL 8

Expert Comment

by:trestan
ID: 1170377
I think you are making your first windows programm which is usually the "Hello world" program. I think you are not using the AppWizard to create the project. If so, you should make change in your project setting. In link tab, you should change the console to windows in the subsystem option. As of the nafxcwd.lib, you should link the lib with your project if you use some functions in it. Finally, I do not know how you know about C++, if you are learning C++, I suggest you not to use MFC at first. HOpe it helps.
0
 

Author Comment

by:gen_genesis
ID: 1170378
I used Win32 Application to create the project.

What should I make change in my project setting
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170379
Win32 Application is used for maing a win32 application that doesn't use MFC.  (Or where you manually include the MFC libraries and include files.)   You should create a new project and specify MFC application as the project type.  This creates a win32 application that links with the MFC libraries.
0
 
LVL 2

Expert Comment

by:WDB
ID: 1170380
It's O.K. to use Win32 application for this project.
 From development studio Go to Project - Settings - C/C++. Select the Code Generation category. Set the Use run-time library to Debug Multithreaded. Then rebuild. Your .exe will compile without error.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:gen_genesis
ID: 1170381
After I changed the setting, it still have error.

--------------------Configuration: Dailup - Win32 Debug--------------------
Compiling...
Dailup.cpp
Linking...
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Dailup.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Dailup.exe - 2 error(s), 0 warning(s)

0
 
LVL 2

Expert Comment

by:WDB
ID: 1170382
I copied your code and created a Win32 app with it and made the change I suggested to you and it works fine. I assure you that this is the correct answer.
0
 
LVL 2

Expert Comment

by:Slarti
ID: 1170383
May I suggest that you create a new project with WDB's specs and copy the source to this new project. There is obviously some config mismatch between gen_genesis's and wdb's projects.
0
 
LVL 1

Expert Comment

by:jdyer
ID: 1170384
FOLLOW _WDB_'s instructions and everything will turn out FINE!

Regards,
  jdyer
0
 
LVL 23

Accepted Solution

by:
chensu earned 20 total points
ID: 1170385
Create the project as follows:
1. Select the menu File/New...;
2. Select the Win32 Application project type;
3. Select the menu Project/Add to Project/Files... and select your existing .cpp;
4. Select the menu Project/Settings..., under the General tab, select Use MFC in a Static Library (or Shared DLL) for Microsoft Foundation Classes.
5. Build it.

You just missed out the step 4. nietod was almost there.
0
 

Expert Comment

by:hariseldon
ID: 1170386
Try changing the general settings for MFC from statically linked to shared DLLs. It worked for me.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now