Re: ATL and MFC causing link error - LNK2019: unresolved external
If I do as you ask then the project hosting these classes no longer compiles.
My other non-ATL-based projects do not need that re-arrangement.
Why does this ATL-based project need the code different?
Are there settings I can change in the project?
here is my stdafx.h....
//#if !defined(AFX_STDAFX_H__698a6960-1ea3-11dc-81ae-00197d6b5501__INCLUDED_)
//#define AFX_STDAFX_H__698a6960-1ea3-11dc-81ae-00197d6b5501__INCLUDED_
#pragma warning (disable : 4503)
#pragma warning (disable : 4786)
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define STRICT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#define _ATL_APARTMENT_THREADED
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h>
#include <afxdisp.h>
//#include <afxtempl.h>
//#include <afxmt.h>
#include <afxext.h>
#include <atlbase.h>
#include <winsvc.h>
//maximum number of character size allowed for service
#define MAX_ATL_SERVICE_NAME_SIZE 256
//You may derive a class from CComModule and use it if you want to override
//something, but do not change the name of _Module
class CServiceModule : public CComModule
{
public:
HRESULT RegisterServer(BOOL bRegTypeLib, BOOL bService);
HRESULT UnregisterServer();
void Init(_ATL_OBJMAP_ENTRY* p, HINSTANCE h, UINT nServiceNameID, const
GUID* plibid = NULL);
void Start();
void ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
void Handler(DWORD dwOpcode);
void Run();
BOOL IsInstalled();
BOOL Install();
BOOL Uninstall();
LONG Unlock();
void LogEvent(DWORD EventType, DWORD EventId);
void SetServiceStatus(DWORD dwState);
void SetupAsLocalServer();
//Implementation
private:
static void WINAPI _ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
static void WINAPI _Handler(DWORD dwOpcode);
// data members
public:
TCHAR m_szServiceName[MAX_ATL_SERVICE_NAME_SIZE];
SERVICE_STATUS_HANDLE m_hServiceStatus;
SERVICE_STATUS m_status;
DWORD dwThreadID;
BOOL m_bService;
};
extern CServiceModule _Module;
#include <atlcom.h>
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately
before the previous line.
//#endif //
!defined(AFX_STDAFX_H__698a6960-1ea3-11dc-81ae-00197d6b5501__INCLUDED)
Here is my compiler command line....
/Od /I "..\..\Utilities" /I "..\..\STLport\stlport" /I
"..\..\products\Common" /I "..\..\products\MySTL" /I
"..\..\products\ThreadApi" /D "NDEBUG" /D "_WINDOWS" /D "_ATL_DLL" /D
"_AFXDLL" /D "_MBCS" /FD /EHsc /MD /Yu"stdafx.h" /Fp"Release\MyManager.pch"
/Fo"Release\\" /Fd"Release\MyManager.pdb" /W3 /nologo /c /Wp64 /Zi /Gd /TP
/errorReport:prompt
Here is my linker command line...
/VERBOSE /OUT:"..\..\Products\Release\MyManager.exe" /INCREMENTAL:NO /NOLOGO
/LIBPATH:"..\..\stlport\lib" /LIBPATH:"..\..\products\release" /MANIFEST
/MANIFESTFILE:"..\..\products\Release\MyManager.exe.intermediate.manifest"
/NODEFAULTLIB /IGNOREIDL /DEBUG /PDB:"..\..\products\release\MyManager.pdb"
/SUBSYSTEM:WINDOWS /MACHINE:X86 /ERRORREPORT:PROMPT stlport.5.1.lib MFC80.lib
mfcs80.lib MSVCrt.lib Kernel32.lib user32.lib msimg32.lib comdlg32.lib
winspool.lib advapi32.lib shell32.lib comctl32.lib shlwapi.lib uuid.lib
oledlg.lib ole32.lib oleaut32.lib urlmon.lib atl.lib atls.lib Utilities.lib
MySTL.lib Common.lib ThreadAPI.lib wbemuuid.lib wmiutils.lib
"Giovanni Dicanio" wrote:
"Lisa L" <llombardo@nospam.nospam> ha scritto nel messaggio
news:CDD2A9DD-86B5-49CE-A0AE-DCF3B59C612B@microsoft.com...
I still get the same LINK error
1>MyManager.obj : error LNK2019: unresolved external symbol "protected:
__thiscall CSingletonObj::CSingletonObj(void)" (??0CSingletonObj@@IAE@XZ)
referenced in function "private: __thiscall CMyManager::CMyManager(void)"
(??0CMyManager@@AAE@XZ)
Here is some code...
In the H file.
class CSingletonObj
{
public:
/// Destructor
virtual ~CSingletonObj() {};
protected:
/// Constructor
CSingletonObj();
};
Could you try the following, please?
Adjust the above code putting the CSingletonObj ctor implementation inside
class definition, i.e.:
class CSingletonObj
{
public:
virtual ~CSingletonObj() {};
protected:
CSingletonObj()
{
// Autoregister with the CSingletonMgr
CSingletonMgr::Register(this);
}
};
Then in the CPP file remove the CSingletonObj ctor definition.
(Make sure that CSingletonMgr is defined before CSingletonObj.)
Giovanni