Re: Why do I get LNK2001 unresolved _main symbol error with this code

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Alexander Nickolov (agnickolov_at_mvps.org)
Date: 09/21/04


Date: Tue, 21 Sep 2004 09:02:48 -0700

Could the fact you have commas instead of plain spaces in #import
play tricks with you? Otherwise it looks fine...

-- 
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Angus Comber" <ac@NOiteloffice.com.PLEASENOSPAM> wrote in message 
news:O3$dkU%23nEHA.2840@TK2MSFTNGP10.phx.gbl...
>I tried going into Project... Settings then Link tab and ticked 'Ignore all
> default libraries.
>
> Then When I recompiled got this output:
>
> Linking...
> maindlg.obj : error LNK2001: unresolved external symbol "class _variant_t
> vtMissing" (?vtMissing@@3V_variant_t@@A)
> maindlg.obj : error LNK2001: unresolved external symbol __alloca_probe
> Raw_DAO.obj : error LNK2001: unresolved external symbol
> __imp__InitCommonControlsEx@4
> Release/Raw_DAO.exe : fatal error LNK1120: 3 unresolved externals
> Error executing link.exe.
>
> I removed any vtMissing from my code but still got the same output.
>
> vtMissing is in the DAO360.tlh file (which is generated from the #import.
> My #import is this:
>
> #import "E:\Program files\Common files\Microsoft Shared\DAO\DAO360.DLL"
> rename_namespace("DAOIO") rename("EOF","EndOfFile") raw_interfaces_only,
> raw_native_types, named_guids
> using namespace DAOIO;
>
> Do I need to modify my #import line?
>
> Angus Comber
> angus@NOSPAMiteloffice.com
>
>
>
> "Alexander Nickolov" <agnickolov@mvps.org> wrote in message
> news:#GYa5kpnEHA.2612@TK2MSFTNGP15.phx.gbl...
>> Add the CRT implib to the list of ignored libraries and
>> the linker will tell you what you used from CRT and in
>> what object file.
>>
>> --
>> =====================================
>> Alexander Nickolov
>> Microsoft MVP [VC], MCSD
>> email: agnickolov@mvps.org
>> MVP VC FAQ: http://www.mvps.org/vcfaq
>> =====================================
>> "Angus Comber" <ac@NOiteloffice.com.PLEASENOSPAM> wrote in message
>> news:eQ%23ZlzinEHA.1248@TK2MSFTNGP09.phx.gbl...
>> > Hello
>> >
>> > I am getting this link error:
>> >
>> > LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
>> >
>> > With code which I don't believe uses the C Runtime.
>> >
>> > Here is the code:
>> >
>> > // DBAccess.h: interface for the CDBAccess class.
>> > // Wraps Database access technology - this one specific to DAO / MS
> Access
>> > // However, would be easy to create eg ADO/SQL Server version
>> > //
>> > //////////////////////////////////////////////////////////////////////
>> > #ifndef __DBACCESS_H__
>> > #define __DBACCESS_H__
>> > // Use 'raw_interfaces_only' to suppress the generation of
> error-handling
>> > wrapper functions
>> > #import "E:\Program files\Common files\Microsoft Shared\DAO\DAO360.DLL"
>> > rename_namespace("DAOIO") rename("EOF","EndOfFile") named_guids
>> > raw_interfaces_only
>> > using namespace DAOIO;
>> > #if _MSC_VER > 1000
>> > #pragma once
>> > #endif // _MSC_VER > 1000
>> > class CDBAccess
>> > {
>> > public:
>> > HRESULT CloseEverything()
>> > {
>> > BOOL b = spDB->Close();
>> > spDB.Release();
>> > spEngine.Release();
>> > return S_OK;
>> > }
>> > HRESULT DoIt()
>> > {
>> > HRESULT hr = 0;
>> > LPCLASSFACTORY2 pCF2; // ClassFactory2 because MS use licencing for DAO
>> > BSTR varKey = SysAllocString(L"mbmabptebkjcdlgtjmskjwtsdhjbmkmwtrak");
>> > // Because Microsoft use licencing, use CF2
>> > hr = CoGetClassObject(CLSID_DBEngine, /*clsidEngine,*/
>> > CLSCTX_INPROC_SERVER,
>> > NULL,
>> > IID_IClassFactory2, (LPVOID*)&pCF2);
>> > if (hr != 0)
>> > {
>> > MessageBox(0, "Error extracting DAO ClassFactory. Database support may
> not
>> > be installed. Call Itel Office support for assistance", "DAO Database
>> > Error", MB_ICONEXCLAMATION);
>> > CoUninitialize();
>> > return 2;
>> > }
>> > // Create licence using licence key - this then produces a valid 
>> > pEngine
>> > even if Access not installed
>> > hr = pCF2->CreateInstanceLic(NULL, NULL, IID__DBEngine, //refid,
>> > //guidEngine,
>> > varKey, (LPVOID*)&spEngine);
>> > if (hr != 0)
>> > {
>> > MessageBox(0, "Error creating DAO licence. Database support may not be
>> > installed. Call Itel Office support for assistance", "DAO Database
> Error",
>> > MB_ICONEXCLAMATION);
>> > CoUninitialize();
>> > return 3;
>> > }
>> > // Finished with CF2 pointer now
>> > pCF2->Release();
>> > // Free BSTR mem
>> > SysFreeString(varKey);
>> >
>> > CComBSTR bstrName = "C:\\mydb.mdb";
>> > CComBSTR bstrConnect = dbLangGeneral;
>> > CComVariant option = dbVersion30;
>> > hr=spEngine->CreateDatabase(bstrName, bstrConnect, option, &spDB);
>> > // Check spDB not null - eg if file already exists.
>> > if (spDB.p == NULL)
>> > {
>> > }
>> >
>> > return S_OK;
>> > }
>> > HRESULT RunActionSQL(TCHAR* szSQL)
>> > {
>> > if (spDB == NULL)
>> > return E_FAIL;
>> > CComBSTR bstrSQL = szSQL;
>> > HRESULT hr=spDB->Execute(bstrSQL);
>> > return hr;
>> > }
>> > CComPtr<DAOIO::_DBEngine> spEngine;
>> > CComPtr<DAOIO::Database> spDB;
>> > };
>> >
>> > #endif // __DBACCESS_H__
>> >
>> > Then from my maindlg (WTL project) I have:
>> >
>> > CDBAccess mydb;
>> > HRESULT hr=mydb.DoIt();
>> > hr=mydb.RunActionSQL("CREATE TABLE Types (Type TEXT(100))");
>> > hr=mydb.CloseEverything();
>> > EndDialog(wID);
>> >
>> > Why would this be using thne C runtime?  Do I need to specify anything
>> > elsei
>> > n my #import directive?
>> >
>> > Angus Comber
>> > angus@NOSPAMiteloffice.com
>> >
>> >
>>
>>
>
> 


Relevant Pages