2

I installed Visual Studio Community 2015 on a fairly fresh Win10 install that never had any IDEs/dev tools installed on it.

I made an empty c++ project, added main.cpp, set the entry point to main and added:

void main()
{

}

On VS2013 I could do this without any issues. I am getting linker errors with this that I haven't been able to figure out:

Severity    Code    Description File    Line
Error   LNK2019 unresolved external symbol __CrtDbgReport referenced in function __CRT_RTC_INIT C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\MSVCRTD.lib(_init_.obj) 1
Error   LNK2019 unresolved external symbol __CrtDbgReportW referenced in function __CRT_RTC_INITW   C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\MSVCRTD.lib(_init_.obj) 1
Error   LNK2019 unresolved external symbol ___stdio_common_vsprintf_s referenced in function __vsprintf_s_l C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\MSVCRTD.lib(_error_.obj)    1
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)    C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\MSVCRTD.lib(_pdblkup_.obj)  1
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)   C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\MSVCRTD.lib(_pdblkup_.obj)  1
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)    C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\MSVCRTD.lib(_pdblkup_.obj)  1
Error   LNK2019 unresolved external symbol ___vcrt_GetModuleFileNameW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)  C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\MSVCRTD.lib(_pdblkup_.obj)  1
Error   LNK2019 unresolved external symbol ___vcrt_GetModuleHandleW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)    C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\MSVCRTD.lib(_pdblkup_.obj)  1
Error   LNK2019 unresolved external symbol ___vcrt_LoadLibraryExW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)  C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\MSVCRTD.lib(_pdblkup_.obj)  1
Error   LNK2019 unresolved external symbol __except_handler4_common referenced in function __except_handler4    C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\MSVCRTD.lib(_chandler4gs_.obj)  1
Error   LNK1120 10 unresolved externals C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\Debug\ConsoleApplication1.exe   1

Update:

I changed two configuration properties:

  • Linker > Input > Ignore All Default Libraries > Yes (/NODEFAULTLIB)
  • C/C++ > Code Generation > Basic Runtime Checks > Default

This let me build the above code however after adding some other trivial code, I am getting a slew of other issues:

#include <string>

using namespace std;

void main()
{
    string blah = "string";
}

It should be trivial to include a standard library and yet:

Severity    Code    Description File    Line
Error   LNK2019 unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) referenced in function "void * __cdecl std::_Allocate(unsigned int,unsigned int,bool)" (?_Allocate@std@@YAPAXII_N@Z)  C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) referenced in function "void __cdecl std::_Deallocate(void *,unsigned int,unsigned int)" (?_Deallocate@std@@YAXPAXII@Z)    C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol __imp___invalid_parameter referenced in function "void * __cdecl std::_Allocate(unsigned int,unsigned int,bool)" (?_Allocate@std@@YAPAXII_N@Z)   C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Lockit::_Lockit(int)" (__imp_??0_Lockit@std@@QAE@H@Z) referenced in function "public: void __thiscall std::_Container_base12::_Orphan_all(void)" (?_Orphan_all@_Container_base12@std@@QAEXXZ)    C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Lockit::~_Lockit(void)" (__imp_??1_Lockit@std@@QAE@XZ) referenced in function "public: void __thiscall std::_Container_base12::_Orphan_all(void)" (?_Orphan_all@_Container_base12@std@@QAEXXZ)   C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol _memcpy referenced in function "public: static char * __cdecl std::char_traits<char>::copy(char *,char const *,unsigned int)" (?copy@?$char_traits@D@std@@SAPADPADPBDI@Z)    C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol __imp__memmove referenced in function "public: static char * __cdecl std::char_traits<char>::move(char *,char const *,unsigned int)" (?move@?$char_traits@D@std@@SAPADPADPBDI@Z) C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol _strlen referenced in function "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z)    C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol __imp___CrtDbgReportW referenced in function "void * __cdecl std::_Allocate(unsigned int,unsigned int,bool)" (?_Allocate@std@@YAPAXII_N@Z)   C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol "__declspec(dllimport) void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (__imp_?_Debug_message@std@@YAXPB_W0I@Z) referenced in function "void __cdecl std::_Debug_pointer<char const >(char const *,wchar_t const *,unsigned int)" (??$_Debug_pointer@$$CBD@std@@YAXPBDPB_WI@Z)   C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xbad_alloc(void)" (__imp_?_Xbad_alloc@std@@YAXXZ) referenced in function "void * __cdecl std::_Allocate(unsigned int,unsigned int,bool)" (?_Allocate@std@@YAPAXII_N@Z) C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z) referenced in function "public: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Xlen(void)const " (?_Xlen@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEXXZ)  C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z) referenced in function "public: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Xran(void)const " (?_Xran@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEXXZ)  C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol @__security_check_cookie@4 referenced in function __unwindfunclet$??0?$_String_alloc@U?$_String_base_types@DV?$allocator@D@std@@@std@@@std@@QAE@ABV?$allocator@D@1@@Z$0  C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol __CxxThrowException@8 referenced in function __catch$?_Copy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXII@Z$1  C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol ___CxxFrameHandler3 referenced in function __unwindfunclet$??0?$_String_alloc@U?$_String_base_types@DV?$allocator@D@std@@@std@@@std@@QAE@ABV?$allocator@D@1@@Z$0 C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2019 unresolved external symbol ___security_cookie referenced in function "public: __thiscall std::_String_alloc<struct std::_String_base_types<char,class std::allocator<char> > >::_String_alloc<struct std::_String_base_types<char,class std::allocator<char> > >(class std::allocator<char> const &)" (??0?$_String_alloc@U?$_String_base_types@DV?$allocator@D@std@@@std@@@std@@QAE@ABV?$allocator@D@1@@Z) C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\main.obj    1
Error   LNK2001 unresolved external symbol __load_config_used   C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\ConsoleApplication1\LINK    1
Error   LNK1120 18 unresolved externals C:\Users\[user]\Desktop\VS_TEST\ConsoleApplication1\Debug\ConsoleApplication1.exe   1
Enigma
  • 1,247
  • 3
  • 20
  • 51
  • I just started an empty C++ Console Application project, added a c++ file, put `void main() { }` in it, and it works fine (you did select *Console Application*, right?) – crashmstr Feb 24 '16 at 16:17
  • Yes I did select *Console Application*. – Enigma Feb 24 '16 at 16:20
  • 1
    Related, possibly duplicate: [Visual studio 2015 c++ and assembly not building](http://stackoverflow.com/questions/33577341/visual-studio-2015-c-and-assembly-not-building) – crashmstr Feb 24 '16 at 16:22
  • @crashmstr - thanks that helped but now is throwing issues. – Enigma Feb 24 '16 at 16:43
  • 1
    Looks like you are still missing library or other project configuration settings. – crashmstr Feb 24 '16 at 16:45
  • Yeah I don't disagree but I am baffled at how this isn't possible right out of the gate. It's as if VSC was crippled. It's not like I'm doing some new revolutionary thing here. This is effectively the hello world test. I could do this exact thing back on VS2013 without fussing in the properties. – Enigma Feb 24 '16 at 16:51
  • I'm not able to reproduce your problem, but perhaps try creating the project again without the "empty" selection? – crashmstr Feb 24 '16 at 16:53
  • Yup, Ok. I made another console application without empty checked off and sure enough, it builds with `` and without having to twerk the properties. – Enigma Feb 24 '16 at 16:57
  • 1
    This may or may not have to do with the pre-compiled header being in a non-empty project. I'd like to be able to do what I'm trying to do without any PCHs. – Enigma Feb 24 '16 at 18:19
  • 3
    Side note: `void main` is wrong. – deviantfan Feb 24 '16 at 20:37
  • @deviantfan What makes it wrong? – Enigma Feb 24 '16 at 20:39
  • 3
    @Enigma The C++ standard allows only `int` as return type for main. Microsoft is notorious for not caring much (especially in older versions of it's software), but if you want C++ code which runs on other compilers (and/or future versions of VS if they get better), don't do it. – deviantfan Feb 24 '16 at 20:41
  • Thanks good tip. May migrate it to eclipse someday. – Enigma Feb 24 '16 at 20:44
  • 1
    @Enigma ...and the void/int problem is only the tip of the iceberg :) If you like VS but want compatible code, it helps much to make occasional builds with some other compiler while developing, every few days or so, just to check if there are errors not shown in VS. (at the same time, you'll get a good "feeling" what code to avoid in VS) – deviantfan Feb 24 '16 at 20:49
  • @deviantfan Yeah great idea. I was actually thinking of doing something like that soon. – Enigma Feb 24 '16 at 20:51

1 Answers1

3

Ok I figured it out but it leads to another question.

The problem was both that I was defining /ENTRY:Main in Linker > Advanced > Entry Point in addition to the entry point being Main and not main.

All the paths/libraries were all in order, surprisingly. I undid the changes to the configuration mentioned under the "Update:" line in the question - that wasn't the issue.

What makes this really weird is that I absolutely could do exactly that above in Visual Studio 2013 (from which I migrated the project). Perhaps even weirder.. I have another project that I also migrated in the same fashion that also has Main specifically declared as the entry point and yet it gets no complaints from the linker.

Enigma
  • 1,247
  • 3
  • 20
  • 51