I wish to compile simple Microsoft Foundation Class programs at
the command line in Visual Studio.net.
I already got simple Windows API programs to compile at the command line
in Visual Studio.net. This was thanks to help from someone on the complang.c
newsgroup.

Last century, I made a simple make file
to compile (see below), to do so under Visual C++ 6.0 tools:

Here is what I tried today:


cl hello.cpp c:\progra~1\micros~1.net\Vc7\PlatformSDK\lib\user3 2.lib

where the hello.cpp is:

__________________________________________________ ___________________

#include

class CMainWindow: public CFrameWnd
{
public:
int mousecount;
CMainWindow ();
afx_msg void OnPaint ();
afx_msg void OnLButtonDown (UINT , CPoint);
DECLARE_MESSAGE_MAP();
};

class CTheApp: public CWinApp
{
public :
BOOL InitInstance ();
};

CTheApp theApp;

CMainWindow::CMainWindow ()
{
Create (NULL, "Hello Foundation Applicaton",WS_OVERLAPPEDWINDOW, rectDefault,
NULL,NULL);
}

void CMainWindow ::OnPaint ()
{
char s[100];
sprintf (s,"%d",mousecount);
CPaintDC dc (this);
CRect rect;

GetClientRect (rect);
dc.TextOut ((rect.right / 2), (rect.bottom /2),s,strlen(s));
}

void CMainWindow :: OnLButtonDown (UINT nFlags, CPoint point) {
mousecount ++;
InvalidateRect(NULL,TRUE);
}

BEGIN_MESSAGE_MAP (CMainWindow,CFrameWnd)
ON_WM_PAINT ()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP ()

BOOL CTheApp:: InitInstance ()
{
m_pMainWnd = new CMainWindow ();
m_pMainWnd -> ShowWindow (m_nCmdShow);
m_pMainWnd -> UpdateWindow ();
return TRUE;
}
__________________________________________________ ___

I get the error:


(STU) C:\WINDOWS\Temp>cl hello.cpp c:\progra~1\micros~1.net\Vc7\PlatformSDK\lib\user3 2.lib
hello.cpp
Microsoft (R) Incremental Linker Version 7.00.9466
Copyright (C) Microsoft Corporation. All rights reserved.

/out:hello.exe
hello.obj
c:\progra~1\micros~1.net\Vc7\PlatformSDK\lib\user3 2.lib
nafxcw.lib(thrdcore.obj) : error LNK2019: unresolved external symbol __endthreadex referenced in function "void __stdcall AfxEndThread(unsigned int,int)" (?AfxEndThread@@YGXIH@Z)
nafxcw.lib(thrdcore.obj) : error LNK2019: unresolved external symbol __beginthreadex referenced in function "public: int __thiscall CWinThread::CreateThread(unsigned long,unsigned int,struct _SECURITY_ATTRIBUTES *)" (?CreateThread@CWinThread@@QAEHKIPAU_SECURITY_ATTR IBUTES@@@Z)
libc.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
hello.exe : fatal error LNK1120: 3 unresolved externals

__________________________________________________ __________

In the MSDN web site, I saw article 140584. This discussed linking with
"the correct C Run-TIme Library" and advised regarding
the following switches:
/ML /MT /MD /MLd /MTd /MDd

None of these worked; often I got the same error message; sometimes, it
could not find my main program.

I use the command line in my teaching so the students can focus on the
important parts of the programming.

Here is how I compiled MFC programs last century, under the command line
compiler.

First, I run this batch file.

CALL c:\progra~1\micros~1\vc98\bin\vcvars32.bat x86
set PATH=%path%;c:\progra~1\micros~1\vc98\bin

SET CFLAGS=-c -DSTRICT -G3 -Ow -W3 -Zp -Tp
SET CFLAGSMT=-c -DSTRICT -G3 -MT -Ow -W3 -Zp -Tp
SET MFCFLAGS=-c -DSTRICT -G3 -Ow -Zp -MD -D "WIN32" -D "_WINDOWS" -D "_AFXDLL" -D "_MBCS"
SET LINKER=link
SET GUIFLAGS=-SUBSYSTEM:windows
SET GUILIBS=-DEFAULTLIB:user32.lib gdi32.lib winmm.lib comdlg32.lib comctl32.lib
SET RC=rc
SET RCVARS=-r -DWIN32


Then, I used this make file:


all : hello.exe

hello.exe : hello.obj
$(LINKER) $(GUIFLAGS) -OUT:hello.exe hello.obj

hello.obj: hello.cpp
$(CC) $(MFCFLAGS) HELLO.CPP