这就是事情,伙计们:
我在尝试使我的程序的入口点不被称为main
时遇到了麻烦
之前,在Visual Studio 2012中非常简单 - 我只使用了链接器的/ENTRY
键或我项目的相同设置(Project->' project_name' properties ...-> Linker - > Advanced-> Entry Point)它运行正常:比方说,我有这样的功能:
int LetsRock
{
...
return 0;
}
如上所述,我需要设置/ENTRY:LetsRock
并先运行。
但在 Microsoft Visual Studio 2015企业版14.0.25123.00更新2 事情变得非常奇怪:
当我重新定义入口点时,编译器会给我一堆11个错误(实际上是10,'因为第11个只说,有10个错误):
对于那些不想打开图片的人来说,他们是这样的:
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 ==========
事实证明甚至更奇怪 - 如果我将入口点设置设置为main
(当然,这里我也在源文件中重命名我的功能),它仍然无法正常工作。同样的错误。
所以,问题是:
如何在Visual Studio 2015中正确地重新定义C / C ++项目的入口点?
如果这是不可能的,为什么他们终于取消了这个设置呢?
答案 0 :(得分:1)
好的,正如Hans Passant建议的那样,我刚刚添加了更多.lib
个依赖项:vcruntimed.lib
和ucrtd.lib
,并且运行正常。它是在Release
配置中编译的,没有那些库,但是这样它可能无法正常运行 - 在我的情况下,程序
#include <stdio.h>
int LetsRock()
{
getchar();
return 0;
}
没有跑,说error LNK2001: unresolved external symbol __imp__getchar