在 Microsoft Visual Studio 2015 中重新定义 C/C++ 入口点 [英] Redifining C/C++ entry point in Microsoft Visual Studio 2015

查看:98
本文介绍了在 Microsoft Visual Studio 2015 中重新定义 C/C++ 入口点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事情是这样的,伙计们:
我在尝试使我的程序的入口点不被称为 main
时遇到了麻烦早些时候,在 Visual Studio 2012 中,这很容易 - 我只是使用了链接器的 /ENTRY 键或我的项目的相同设置(Project->'project_name' properties...->Linker->Advanced->入口点)并且它工作正常:比如说,我有一个这样的功能:

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;
}

我需要,如上所述,只需设置 /ENTRY:LetsRock,然后它首先运行.

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

但是在 Microsoft Visual Studio 2015 Enterprise Version 14.0.25123.00 Update 2 中,事情变得很奇怪:

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

一旦我重新定义入口点,编译器就会给我一堆 11 个错误(实际上是 10 个,因为第 11 个只说有 10 个错误):

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):

给那些不想打开图片的人:

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 ==========

结果更奇怪 - 如果我将入口点设置设置为 main(当然,这里我也在源文件中重命名了我的函数),它仍然不起作用.同一组错误.

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.

那么,问题是:
如何在 Visual Studio 2015 中正确地重新定义 C/C++ 项目的入口点?

如果这是不可能的,为什么他们最终没有删除此设置?

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?

推荐答案

好的,正如 Hans Passant 所建议的,我刚刚添加了更多的 .lib 依赖项:vcruntimed.libucrtd.lib,它运行良好.它是在没有这些库的 Release 配置中编译的,但这样它可能无法正常工作 - 在我的情况下,程序

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;
}

没有运行,说error LNK2001: unresolved external symbol __imp__getchar

这篇关于在 Microsoft Visual Studio 2015 中重新定义 C/C++ 入口点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆