1

Here's the thing, guys:
I've got a trouble trying to make the entry point of my program not called main
Earlier, in Visual Studio 2012 that was pretty easy - I just used /ENTRY key of linker or the same setting of my project (Project->'project_name' properties...->Linker->Advanced->Entry Point) and it worked properly: say, I had a function like this:

int LetsRock
{
    ...
    return 0;
}

And I needed, as described above, just set /ENTRY:LetsRock and it ran first.

But in Microsoft Visual Studio 2015 Enterprise Version 14.0.25123.00 Update 2 things turn out quite strange:

As soon as I redefine the entrypoint, compiler gives me the bunch of 11 errors (actually 10, 'cause 11th only says, that there are 10 errors):

errors list

Here they are, for those, who don't wanna open the picture:

1>------ Build started: Project: Tester, Configuration: Debug Win32 ------
1>  Source.c
1>MSVCRTD.lib(_init_.obj) : error LNK2019: unresolved external symbol __CrtDbgReport referenced in function __CRT_RTC_INIT
1>MSVCRTD.lib(_init_.obj) : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function __CRT_RTC_INITW
1>MSVCRTD.lib(_error_.obj) : error LNK2019: unresolved external symbol ___stdio_common_vsprintf_s referenced in function __vsprintf_s_l
1>MSVCRTD.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol __wmakepath_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)" (?GetPdbDllPathFromFilePath@@YAHPB_WPA_WI@Z)
1>MSVCRTD.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol __wsplitpath_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)" (?GetPdbDllPathFromFilePath@@YAHPB_WPA_WI@Z)
1>MSVCRTD.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol _wcscpy_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)" (?GetPdbDllPathFromFilePath@@YAHPB_WPA_WI@Z)
1>MSVCRTD.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol ___vcrt_GetModuleFileNameW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)
1>MSVCRTD.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol ___vcrt_GetModuleHandleW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)
1>MSVCRTD.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol ___vcrt_LoadLibraryExW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)
1>MSVCRTD.lib(_chandler4gs_.obj) : error LNK2019: unresolved external symbol __except_handler4_common referenced in function __except_handler4
1>C:\<path to my folder>\Tester\Debug\Tester.exe : fatal error LNK1120: 10 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

It turns out even stranger - if I set entrypoint setting to main (of course, here I also rename my function in the source file), it still doesn't work. The same set of errors.

So, the question is:
How do I properly redefine the entry point of C/C++ project in Visual Studio 2015?

If this is impossible, why haven't they, finally, removed this setting?

RedRidingHood
  • 568
  • 3
  • 16
  • 3
    It is done [*very* differently in VS2015](https://blogs.msdn.microsoft.com/vcblog/2015/03/03/introducing-the-universal-crt/). Since you are bypassing the C-runtime initialization you also no longer get the implicit link demands. You'll have to take care of this yourself now, Project > Properties > Linker > Input > Additional Dependencies and add vcruntimed.lib and ucrtd.lib. Do keep in mind how inappropriate this is, you are compiling with Debug configuration settings but are not initializing the debug features of the CRT. – Hans Passant Oct 14 '16 at 13:57
  • @HansPassant Yeah, my thanks - with the additional libs you advised it compiled fine. – RedRidingHood Oct 14 '16 at 14:26

1 Answers1

1

Ok, as Hans Passant advised, I just added more .lib dependencies: vcruntimed.lib and ucrtd.lib, and it worked fine. It is compiled in Release configuration without those libs, but in this way it may not wok correctly - In my case, the program

#include <stdio.h>

int LetsRock()
{
    getchar();
    return 0;
}

didn't run, saying error LNK2001: unresolved external symbol __imp__getchar

Community
  • 1
  • 1
RedRidingHood
  • 568
  • 3
  • 16
  • Well, that would be another example of bad code. Since you bypassed the CRT initialization, you cannot call *any* CRT function. You did not initialize *stdin*. Maybe it works, maybe it doesn't, maybe it won't work tomorrow. – Hans Passant Oct 14 '16 at 14:56
  • so is it possible to redefine your entry point AND initialize the CRT? – ComradeJoecool Sep 24 '17 at 23:31