Prev: KB831875
Next: ___pioinfo
From: Dimitris Staikos <Dimitris on
I have a DLL VC6 project that I am trying to convert to VC8 (VS2005).
I try to make the project statically link to the CRT but to no avail.
I get the following error:
LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
referenced in function ___tmainCRTStartup

I read various topics on the online help, and one suggested that we should
not use static linking with DLL projects unless we know what we are doing.
However I am starting to wonder if it is at all possible. The reason that I
want to use static linking is to avoid messing up our existing clients (our
DLL is part of an SDK that we sell) with the details of redistributing the
VS2005 DLLs and having them to install them on their machines and on their
clients' machines.

So, is there a way I can overcome this linker error and get myself a nice
DLL that is statically linked to the VC8 CRT?

Thanks!
Dimitris Staikos
From: Igor Tandetnik on
Dimitris Staikos <Dimitris Staikos(a)discussions.microsoft.com> wrote:
> I have a DLL VC6 project that I am trying to convert to VC8 (VS2005).
> I try to make the project statically link to the CRT but to no avail.
> I get the following error:
> LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol
> _main referenced in function ___tmainCRTStartup

It appears that your project is actually trying to build an EXE, not a
DLL. Make sure Project | Properties | General | Configuration Type is
set to Dynamic Library (.dll).
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


From: Dimitris Staikos on
"Igor Tandetnik" wrote:
>
> It appears that your project is actually trying to build an EXE, not a
> DLL. Make sure Project | Properties | General | Configuration Type is
> set to Dynamic Library (.dll).
> --

I wish it were that simple :-)
Project | Properties | General | Configuration Type is indeed set to Dynamic
Library (.dll) If I build the project with /MD or /MDd the DLL builds
successfully.

However, I figured out the solution myself, and it seems like it could be a
VC bug
The error I was getting was:

LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
referenced in function ___tmainCRTStartup

I started wondering what confused VC and made it try to link in crt0.obj,
which is the CRT startup code for statically linked EXEs, instead of
dllcrt0.obj which is the CRT startup code for statically linked DLLs.

Then I noticed that our project was using an alternate name for DllMain,
while the code in dllcrt0.c was expecting the name to be DllMain. So I
removed the /ENTRY linker setting, renamed the entry point to DllMain and...
voila the project compiled and linked successfully.


 | 
Pages: 1
Prev: KB831875
Next: ___pioinfo