I have all the necessary MFC libraries, they are all in a directory called ‘atlmc’. I have creates a copied a simple helloworldmfc.cpp from http://social.msdn.microsoft.com/Forums/en-US/vcmfcatl/thread/c8556098-6f41-42cb-9de6-38ed24c3faf9
Here is the code:
#include <afxwin.h>
class HelloApplication : public CWinApp
{
public:
virtual BOOL InitInstance();
};
HelloApplication HelloApp;
class HelloWindow : public CFrameWnd
{
CButton* m_pHelloButton;
public:
HelloWindow();
};
BOOL HelloApplication::InitInstance()
{
m_pMainWnd = new HelloWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
HelloWindow::HelloWindow()
{
Create(NULL,
"Hello World!",
WS_OVERLAPPEDWINDOW|WS_HSCROLL,
CRect(0,0,140,80));
m_pHelloButton = new CButton();
m_pHelloButton->Create("Hello World!",WS_CHILD|WS_VISIBLE,CRect(20,20,120,40),this,1);
}
I have linked every library file etc that the linker asks for, there are a lot of them. Here is my build command:
C:\Users\Scruffy\Desktop\MSVC>Bin\cl.exe hellomfc.cpp /EHsc /I
atlmfc\include /I Includes /I Includes\Winsdk
atlmfc\lib\amd64\nafxcw.lib Libs\libcmt.lib Libs\Ke rnel32.Lib
Libs\User32.Lib Libs\Gdi32.Lib Libs\MSImg32.Lib Libs\ComDlg32.Lib Lib
s\WinSpool.Lib Libs\AdvAPI32.Lib Libs\Shell32.Lib Libs\ComCtl32.Lib
Libs\ShLwApi .Lib Libs\Uuid.lib atlmfc\lib\amd64\atls.lib
Libs\Ole32.Lib Libs\OleAut32.Lib Li bs\oldnames.lib Libs\WS2_32.Lib
Libs\MsWSock.Lib Libs\OleAcc.Lib Libs\comsuppw.l ib Libs\GdiPlus.lib
Libs\Imm32.Lib Libs\WinMM.Lib Libs\MsXml2.Lib Libs\OleDlg.L ib
Libs\Urlmon.Lib
the compilers response complains about __tmainCRTStartup not being found. As well as some other thing about _WIN32_WINNT not being defines, although that just seems to be a warning, not an error.
Here is the full response from cl.exe after I run my build command through it:
Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Copyright (C) Microsoft Corporation. All rights reserved.hellomfc.cpp
_WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h) Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved./out:hellomfc.exe
hellomfc.obj atlmfc\lib\amd64\nafxcw.lib
Libs\libcmt.lib Libs\Kernel32.Lib Libs\User32.Lib Libs\Gdi32.Lib
Libs\MSImg32.Lib Libs\ComDlg32.Lib Libs\WinSpool.Lib Libs\AdvAPI32.Lib
Libs\Shell32.Lib Libs\ComCtl32.Lib Libs\ShLwApi.Lib Libs\Uuid.lib
atlmfc\lib\amd64\atls.lib Libs\Ole32.Lib Libs\OleAut32.Lib
Libs\oldnames.lib Libs\WS2_32.Lib Libs\MsWSock.Lib Libs\OleAcc.Lib
Libs\comsuppw.lib Libs\GdiPlus.lib Libs\Imm32.Lib Libs\WinMM.Lib
Libs\MsXml2.Lib Libs\OleDlg.Lib Libs\Urlmon.Lib libcmt.lib(crt0.obj) :
error LNK2019: unresolved external symbol main referenced in function
__tmainCRTStartup hellomfc.exe : fatal error LNK1120: 1 unresolved externals
so error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup hellomfc.exe : fatal error LNK1120: 1 unresolved externals
Seems to be the problem. This error basically means that the compiler cannot find an entry point, does it not? If so, MFC apparently has its WinMain burried somewhere in the framework. OK fine, how do I link to it?
It appears you may not be specifying the correct target platform (Windows vs Console) and the latter isn’t being linked in.
Try specifying /SUBSYSTEM:WINDOWS on your command line to tell the linker which startup proc to use. It is a linker flag so it needs to be passed through to the link-phase via /link.