[windev] LIBC.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
Chris Becke
Chris.Becke at derivco.com
Thu Jul 30 07:57:03 GMT 2009
First off, Visual Studio 6 is the last MS Visual Studio version that links against the OS distributed msvcrt.dll
I'd suggest switching to Code::Blox - a nice GCC based ide that links against msvcrt.dll for nice small exe files, but it doesnt contain a resource editor at all.
Next - as to the specific cause of your problem:
When Microsoft put the libc.lib together they put in there .obj files containing the implementation for each and every exe and dll entry point combination - At least 6 entry point implementations - an console and gui exe unicode, console and gui ansi exe, a dll unicode and dll ansi.
Now, these obj files all contain duplicate symbols. But this is not a problem for .lib files - the linker is allowed to search .lib files for an .obj that contains a symbol it does want, and pull in that .obj only, not caring about symbols in other .obj's at all.
The problem comes in that, because youve used your own primary entrypoint, the linker doesn't pull in the "correct" (for your build type) entry point implementation up front.
And, for some reason known only to MS or perhaps even Dinkumware - each of the entry point implementations files includes its own copy of a static variable that basically means "floating_point_support_is_loaded". And, as soon as you use a float, a reference to that symbol is generated.
But now, because of the lack of entry point selection up front, the linker doesn;t know which of the .obj files to load, so it picks the first one - in this case the command line console implementation for ascii whichs entry point has a call to "_main" which as a consequence causes the above error.
There are a couple of ways to go about fixing this...
Find the name of the static variable, and declare it somewhere. You will need to also declare a number of functions that Visual Studio will intrinsically generate references to while doing simple operations on floating point types. Its not incredably tough - a project I worked on did that for a while.
But, after a while it does start getting a bit much - without the CRT entry points you loose the ability to handle excpetions, use the new "safe" c-runtime string methods, cant use the STL, complete support for floats and doubles remains tricky, you can't use static scope initialized c++ objects as their constructors will not be called, a number of debugging features that perform stack validation need to remain turned off, and any CRT function that is remotely state full will be well dodge.
Unless you are comitted to writing strictly C code, you can't write 'modern' C++ while ignoring all that stuff. There is no good cause any more (and since 2003) to be using a string class thats not std::string. CString, MyOwnStringClass etc. are no longer viable propositions unless you really don't care about keeping your skill set remotely current.
Which is why I for one am looking long and hard for something like Code::Blox with Mingw. A gcc based ide - builds against msvcrt.dll - makes writing cross platform code that much easier as there are builds of Code::Blox for Linux, Max and Win32 - all it lacks really is an integrated Resource Editor.
________________________________________
From: windev-bounces at windev.org [windev-bounces at windev.org] On Behalf Of Stephen Hazel [stephen.hazel at gmail.com]
Sent: 30 July 2009 01:02 AM
To: Windev
Subject: [windev] LIBC.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
Env: Win2k+; MSVC7; win32 (no MFC)
Ok, I've been successful slimming down my .exes by
using a custom linker entry point other than
winMainCRTStartup (I use one called AppBoot).
I just use windows funcs and everything's nice and teeny.
But throw in some doubles and math.h funcs like sin() and I get the error in
the subject line...:(
Now, I'm using linker subsystem of windows.
And linker ignoreAllDefaultLibraries of no.
Not sure why it's even looking at mainCRTStartup (instead of winMainCRTStartup).
Has anybody messed with this before?
Failing that, if I go to the free visualc++2005 or 2008,
I lose a resource editor, right?
Is there some free resource editor out there that'll replace it?
Thanks for any help :)
...Steve
--
Windev mailing list at Windev at windev.org
Lost your password? Need to unsubscribe or change your delivery options?
Go to http://lists.windev.org/mailman/listinfo/windev
--
Search the Windev Archives - www.windev.org
#############################################################################################
The information transmitted is intended only for the person or entity to which it
is addressed and may contain confidential and/or privileged material.
Any review, retransmission, dissemination or other use of, or taking of any action
in reliance upon, this information by persons or entities other than the intended
recipient is prohibited. If you received this in error, please contact the sender and
delete the material from any computer.
Furthermore, the information contained in this message, and any attachments thereto, is
for information purposes only and may contain the personal views and opinions of the
author, which are not necessarily the views and opinions of the company.
#############################################################################################
More information about the Windev
mailing list