LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in

Started by
11 comments, last by Evil Steve 16 years, 1 month ago
hi, LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup i am facing the errors but i want to link statically . so i don't want to ignore libc libraries and i have tried with all the subsystems(console and windows) but nothing works . There is no minimum use of ATL also. There is a _DllMainCRTStartup function which is set as the entry and one more thing to note is the file is a .c file . i am quoting this because when i rename the file to .cpp and remove the entry point .its builds without linker errors. But unfortunately i am not allowed to do this.The configuration is Win32/Release. Hope these information is enough. Can any one help at the earliest
Advertisement
___tmainCRTStartup is a EXE file entry point.
_DllMainCRTStartup is a DLL file entry point.

Are you building a DLL or EXE?
i am trying to buid a DLL

When you created the project, did you explicitly create a DLL, or did you just create a Win32 application project?

And what IDE are you using?
S i expl defined as dll . i am buiding in visual studio 2005.

actually while creating i created as win32 application and in that i have selected dll option.
Can you create a minimal project that shows this behaviour? I just created a new DLL project with a .c file with the following contents, and the entry point set in the linker settings, and it links fine:
void __stdcall _DllMainCRTStartup(void* hinstDLL, unsigned long fdwReason, void* lpReserved){}
IT WORKS BUT
try including this code segment with that _DllMainCRTStartup

int test()
{
int *i;
i= (int*) malloc(4);
return 0;
}

it now fails with the same error..

now can you get some idea ..
Quote:Original post by gshankaran
IT WORKS BUT
try including this code segment with that _DllMainCRTStartup

int test()
{
int *i;
i= (int*) malloc(4);
return 0;
}

it now fails with the same error..

now can you get some idea ..

Of course it will fail. You cannot call a CRT function (malloc) in the function that is supposed to initialize the CRT...

Why are you overloading _DllMainCRTStartup anyway ? You do realize that there is a whole ton of stuff you have to manually include in that function for it to work properly (init the CRT, call static ctors, etc) ? Just use DllMain instead.
is there any other way to make it run with the use of _DllMainCRTStartup..
if so can you please help me..what are the changes i should do.
Quote:Original post by gshankaran
is there any other way to make it run with the use of _DllMainCRTStartup..
if so can you please help me..what are the changes i should do.

As I said above, use DllMain. There are very few reasons to use _DllMainCRTStartup instead (eg. if you wrote your own replacement CRT, or if you are targeting a system without CRT), and none of these apply to you.

This topic is closed to new replies.

Advertisement