VisualStudio 2019:将应用从控制台切换到 Windows,出现大量链接器错误

VisualStudio 2019: Switch app from Console to Windows, get tons of linker errors

提问人:Timothy Miller 提问时间:1/6/2021 更新时间:1/6/2021 访问量:1004

问:

我有一个刚刚移植到 Windows 的 OpenGL 应用程序,它作为控制台应用程序运行良好。但是,对于发布版本,我想避免弹出控制台终端窗口。我的理解是,我所要做的就是进入 Properties > Linker > System > SubSystem,并将其从控制台切换到 Windows。我还将入口点更改为 main,这样我就不必做一堆不必要的 #ifdefs。不幸的是,我现在收到了很多链接器错误。我试过在谷歌上搜索它们,但我一无所获。我发现了一些关于缺少对“CRT”的依赖关系,但它已经链接到 MSVCRT.lib。也许有人可以帮助我弄清楚该怎么做。

1>blocklibrary.obj : error LNK2001: unresolved external symbol __CxxFrameHandler4
1>msvcprt.lib(filesystem.obj) : error LNK2001: unresolved external symbol __CxxFrameHandler4
1>MSVCRT.lib(gshandlereh4.obj) : error LNK2001: unresolved external symbol __CxxFrameHandler4
1>blocklibrary.obj : error LNK2001: unresolved external symbol __std_exception_destroy
1>MSVCRT.lib(throw_bad_alloc.obj) : error LNK2001: unresolved external symbol __std_exception_destroy
1>blocklibrary.obj : error LNK2001: unresolved external symbol __std_exception_copy
1>MSVCRT.lib(throw_bad_alloc.obj) : error LNK2001: unresolved external symbol __std_exception_copy
1>blocklibrary.obj : error LNK2001: unresolved external symbol __std_terminate
1>msvcprt.lib(filesystem.obj) : error LNK2001: unresolved external symbol __std_terminate
1>blocklibrary.obj : error LNK2001: unresolved external symbol __imp__invalid_parameter_noinfo_noreturn
1>blocktype.obj : error LNK2001: unresolved external symbol _purecall
1>chunk.obj : error LNK2001: unresolved external symbol __imp_fputc
1>chunk.obj : error LNK2001: unresolved external symbol __imp_fflush
1>chunk.obj : error LNK2001: unresolved external symbol __imp_fclose
1>chunk.obj : error LNK2001: unresolved external symbol __imp_fgetc
1>chunk.obj : error LNK2001: unresolved external symbol __imp__unlock_file
1>chunk.obj : error LNK2001: unresolved external symbol __imp__lock_file
1>chunk.obj : error LNK2001: unresolved external symbol __imp_fwrite
1>chunk.obj : error LNK2001: unresolved external symbol __imp_fgetpos
1>chunk.obj : error LNK2001: unresolved external symbol __imp_setvbuf
1>chunk.obj : error LNK2001: unresolved external symbol __imp_ungetc
1>chunk.obj : error LNK2001: unresolved external symbol __imp_fsetpos
1>chunk.obj : error LNK2001: unresolved external symbol __imp_fread
1>chunk.obj : error LNK2001: unresolved external symbol __imp__fseeki64
1>chunk.obj : error LNK2001: unresolved external symbol __imp__get_stream_buffer_pointers
1>datacontainer.obj : error LNK2001: unresolved external symbol __imp___acrt_iob_func
1>datacontainer.obj : error LNK2001: unresolved external symbol __imp___stdio_common_vfprintf
1>facing.obj : error LNK2001: unresolved external symbol __imp_tolower
1>facing.obj : error LNK2001: unresolved external symbol __imp_atoi
1>facing.obj : error LNK2001: unresolved external symbol __imp_isdigit
1>filelocator.obj : error LNK2001: unresolved external symbol __imp_strcat_s
1>geometry.obj : error LNK2001: unresolved external symbol __imp_lrint
1>glad.obj : error LNK2001: unresolved external symbol __imp_strncmp
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_strncmp
1>glfw3.lib(context.obj) : error LNK2001: unresolved external symbol __imp_strncmp
1>glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __imp_strncmp
1>glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol __imp_free
1>msvcprt.lib(filesystem.obj) : error LNK2001: unresolved external symbol __imp_free
1>glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol __imp_free
1>glfw3.lib(vulkan.obj) : error LNK2001: unresolved external symbol __imp_free
1>glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol __imp_free
1>glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __imp_free
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __imp_free
1>glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol __imp_free
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __imp_free
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol __imp_free
1>glad.obj : error LNK2001: unresolved external symbol __imp_free
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_free
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __imp_free
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol __imp_free
1>glad.obj : error LNK2001: unresolved external symbol strstr
1>glfw3.lib(context.obj) : error LNK2001: unresolved external symbol strstr
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol strstr
1>glad.obj : error LNK2001: unresolved external symbol __imp___stdio_common_vsscanf
1>glfw3.lib(context.obj) : error LNK2001: unresolved external symbol __imp___stdio_common_vsscanf
1>glad.obj : error LNK2001: unresolved external symbol __imp_malloc
1>msvcprt.lib(filesystem.obj) : error LNK2001: unresolved external symbol __imp_malloc
1>main.obj : error LNK2001: unresolved external symbol __imp_exit
1>glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(vulkan.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>main.obj : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>main.obj : error LNK2001: unresolved external symbol __imp___stdio_common_vsprintf_s
1>mesh_parser.obj : error LNK2001: unresolved external symbol __imp_atof
1>mesh_parser.obj : error LNK2001: unresolved external symbol __imp_isspace
1>render.obj : error LNK2001: unresolved external symbol __imp__beginthreadex
1>render.obj : error LNK2001: unresolved external symbol __imp_terminate
1>msvcprt.lib(filesystem.obj) : error LNK2001: unresolved external symbol __imp_terminate
1>stb.obj : error LNK2001: unresolved external symbol __imp_ftell
1>stb.obj : error LNK2001: unresolved external symbol __imp_ferror
1>stb.obj : error LNK2001: unresolved external symbol __imp_realloc
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_realloc
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol __imp_realloc
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol __imp_realloc
1>stb.obj : error LNK2001: unresolved external symbol __imp_fseek
1>stb.obj : error LNK2001: unresolved external symbol __imp_fopen_s
1>stb.obj : error LNK2001: unresolved external symbol __imp_strtol
1>stb.obj : error LNK2001: unresolved external symbol __imp_ldexp
1>stb.obj : error LNK2001: unresolved external symbol __imp_feof
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_strcspn
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_strncpy
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __imp_strncpy
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __imp_strncpy
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_strspn
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_strtoul
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol memcpy
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol memcpy
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol memset
1>glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol memset
1>MSVCRT.lib(utility_desktop.obj) : error LNK2001: unresolved external symbol memset
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol memset
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol memset
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol memset
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol memset
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol __imp_qsort
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __imp_qsort
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol memmove
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol powf
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __imp___stdio_common_vsprintf
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __imp___stdio_common_vsprintf
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol strcmp
1>glfw3.lib(vulkan.obj) : error LNK2001: unresolved external symbol strcmp
1>msvcprt.lib(filesystem.obj) : error LNK2001: unresolved external symbol __imp____lc_codepage_func
1>MSVCRT.lib(new_scalar.obj) : error LNK2001: unresolved external symbol _callnewh
1>MSVCRT.lib(new_scalar.obj) : error LNK2001: unresolved external symbol malloc
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol __vcrt_initialize
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol __vcrt_uninitialize
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol __vcrt_uninitialize_critical
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol __vcrt_thread_attach
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol __vcrt_thread_detach
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol _seh_filter_dll
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol _is_c_termination_complete
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol _configure_narrow_argv
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol _initialize_narrow_environment
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol _initialize_onexit_table
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol _register_onexit_function
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol _execute_onexit_table
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol _crt_atexit
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol _crt_at_quick_exit
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol __acrt_initialize
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol __acrt_uninitialize
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol __acrt_uninitialize_critical
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol __acrt_thread_attach
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol __acrt_thread_detach
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol _cexit
1>MSVCRT.lib(utility.obj) : error LNK2001: unresolved external symbol __C_specific_handler
1>MSVCRT.lib(ehvecdtr.obj) : error LNK2001: unresolved external symbol __C_specific_handler
1>MSVCRT.lib(ehvecctr.obj) : error LNK2001: unresolved external symbol __C_specific_handler
1>MSVCRT.lib(ehvecdtr.obj) : error LNK2001: unresolved external symbol terminate
1>MSVCRT.lib(utility_desktop.obj) : error LNK2001: unresolved external symbol terminate
1>MSVCRT.lib(ehvecdtr.obj) : error LNK2001: unresolved external symbol __current_exception
1>MSVCRT.lib(utility_desktop.obj) : error LNK2001: unresolved external symbol __current_exception
1>MSVCRT.lib(ehvecdtr.obj) : error LNK2001: unresolved external symbol __current_exception_context
1>MSVCRT.lib(utility_desktop.obj) : error LNK2001: unresolved external symbol __current_exception_context
1>MSVCRT.lib(throw_bad_alloc.obj) : error LNK2001: unresolved external symbol _CxxThrowException
1>MSVCRT.lib(delete_scalar.obj) : error LNK2001: unresolved external symbol free
C++ Windows Visual-Studio 链接器错误

评论

1赞 john 1/6/2021
您是否尝试过从头开始创建 Windows 项目?我不知道你是否需要做的就是从控制台切换到Windows(尽管你的经验似乎表明这不是真的),但如果你从头开始创建项目,你可以确保拥有所有正确的设置。
0赞 Timothy Miller 1/6/2021
我想到了。问题是我希望 Debug 有一个控制台,但 Release 没有。我已经将所有代码签入 git 和所有内容。如果我做了一个新项目,那将是一个巨大的麻烦。也许我能做的就是创建一个空的 Windows 项目,然后比较配置文件以查看有什么不同。
0赞 john 1/6/2021
您可以有一个 Windows 程序,该程序在调试模式下手动创建控制台。只是一个建议。
1赞 Timothy Miller 1/6/2021
我想通了。我尝试将入口点设置为main,这就是破坏一切的原因。我使用预处理器根据 _DEBUG 在 main() 和 WinMain 之间进行选择,现在它工作正常。
1赞 john 1/6/2021
@TimothyMiller 很高兴你把它整理好了。你可以把你的经历写下来作为答案,以备将来参考。回答你自己的问题是完全可以的。

答: 暂无答案