无法在Visual Studio社区2015中编译bare minimum void main(){}(LNK2019 - MSVCRTD.lib)

时间:2016-02-24 16:12:58

标签: c++ windows visual-studio linker-errors visual-studio-2015

我在一个相当新的Win10安装上安装了Visual Studio Community 2015,它从未安装过任何IDE / dev工具。

我创建了一个空的c ++项目,添加了main.cpp,将入口点设置为main并添加了最小值:

void main()
{

}

VS2013我可以毫无问题地执行此操作。我收到的链接器错误是我无法弄清楚的:

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

更新

我更改了两个配置属性:

  • Linker > 输入> 忽略所有默认库> Yes (/NODEFAULTLIB)
  • C / C ++ > 代码生成> 基本运行时检查> Default

这让我构建了上面的最小代码,但是在添加了一些其他的简单代码后,我遇到了一些其他问题。我无法理解为什么VSC15会开箱即用:

#include <string>

using namespace std;

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

包含一个标准库应该是微不足道的:

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

1 个答案:

答案 0 :(得分:2)

好的,我发现了它,但它引出了另一个问题。

问题是 我在 Linker &gt;中定义了/ENTRY:Main 高级&gt; 入口点 除了入口点为Main而非main

令人惊讶的是,所有的路径/库都是有序的。我解除了对问题中“更新:”行下提到的配置的更改 - 这不是问题。

这真的很奇怪的是,我绝对可以在Visual Studio 2013中完成上述操作(我从中迁移了项目)。也许更奇怪..我有另一个项目,我也以同样的方式迁移,具有Main专门声明为入口点,但它没有得到链接器的抱怨。

相关问题