Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CComAutoCriticalSection - unresolved symbol _main

Status
Not open for further replies.

ZakiMaksyutov

Programmer
Feb 28, 2001
87
0
0
RU
Hi!

I've encountered with one problem and I don't understand what's wrong.

I created EXE-server with ATL COM AppWizard (free thread, _ATL_FREE_THREADED).
And I use
static CComAutoCriticalSection m_cs; in my class.
I defined this object:
CComAutoCriticalSection MyClass::m_cs;
And all is ok in debug mode. I can compile the project, use it and my critical section works fine. But when I try to compile my project in ReleaseMinDependency, then I get link error L2001: unresolved symbol _main. When I clear away
strings about CComAutoCriticalSection all works again.
Moreover, I can use CComCriticalSection. In this case also works fine. In fact I had to write my class which analog CComAutoCriticalSection:
-------------------------------------
class CComMyAutoCriticalSection
{
public:
CComMyAutoCriticalSection(){
m_cs.Init();
}
~CComMyAutoCriticalSection(){
m_cs.Term();
}
void Lock() { m_cs.Lock(); }
void Unlock() { m_cs.Unlock(); }

private:
CComCriticalSection m_cs;
};
-------------------------------------
Question: what's problem with CComAutoCriticalSection in EXE-server in ReleaseMinDependecy?

Any help will be appreciated.
 
Well.
I wrote class (see above) and all worked fine but later I noticed that I was in debug mode again...
As far as I understood there is following problem:
In EXE-server, built with ATL COM AppWizard (_ATL_FREE_THREADED), in ReleaseMinDependency I can't use any global class objects. F.i. I tried following:

class X
{
public:
X() {}
~X() {}
};
X x;

and got the same error L2001.

I don't know why, but I can use:
class X
{
public:
X() {}
};
X x;

I don't understand...
Can you help me?
 
I found in MSDN:
-----------------------
Note When building a Release version of a project, you can get the following link error:

LIBCMT.LIB(crt0.obj) : error LNK2001: unresolved external symbol _main
This error occurs if you are using CRT functions that require CRT startup code. The Release configurations define _ATL_MIN_CRT, which excludes CRT startup code from your EXE or DLL. To avoid this error, do one of the following:

Remove _ATL_MIN_CRT from the list of preprocessor defines to allow CRT startup code to be included. On the Project menu, click Settings. In the Settings For: drop-down list, choose Multiple Configurations. In the Select project configuration(s) to modify dialog box that appears, click the check boxes for all Release versions, and then click OK. On the C/C++ tab, choose the General category, then remove _ATL_MIN_CRT from the Preprocessor definitions edit box.


If possible, remove calls to CRT functions that require CRT startup code and use their Win32 equivalents. For example, use lstrcmp instead of strcmp. Known functions that require CRT startup code are some of the string and floating point functions.
---------------------
I tried this and all is ok!
Apparently global objects also require CRT startup code.
---------------------

regards,
Zaki
 
I have also had this problem. Removing _ATL_MIN_CRT appeared to be the solution. Depending on what C functions you (or the classes you derive from) use, you can see this in plainly when you have _ATL_MIN_CRT: using something like wcslen() in your class is ok - using mbstowcs() will give you a compile error in AtlMinSize or AtlMinDependency.
--Will Duty
wduty@radicalfringe.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top