<small id='cHJiJ'></small><noframes id='cHJiJ'>

      <tfoot id='cHJiJ'></tfoot>
      • <bdo id='cHJiJ'></bdo><ul id='cHJiJ'></ul>
    1. <i id='cHJiJ'><tr id='cHJiJ'><dt id='cHJiJ'><q id='cHJiJ'><span id='cHJiJ'><b id='cHJiJ'><form id='cHJiJ'><ins id='cHJiJ'></ins><ul id='cHJiJ'></ul><sub id='cHJiJ'></sub></form><legend id='cHJiJ'></legend><bdo id='cHJiJ'><pre id='cHJiJ'><center id='cHJiJ'></center></pre></bdo></b><th id='cHJiJ'></th></span></q></dt></tr></i><div id='cHJiJ'><tfoot id='cHJiJ'></tfoot><dl id='cHJiJ'><fieldset id='cHJiJ'></fieldset></dl></div>

      1. <legend id='cHJiJ'><style id='cHJiJ'><dir id='cHJiJ'><q id='cHJiJ'></q></dir></style></legend>
      2. LNK2019:未解析的外部符号 _main 在函数 ___tmainCRTStartup 中引用

        时间:2023-12-03
          <tfoot id='lBi5q'></tfoot>
          • <small id='lBi5q'></small><noframes id='lBi5q'>

                <tbody id='lBi5q'></tbody>

              <legend id='lBi5q'><style id='lBi5q'><dir id='lBi5q'><q id='lBi5q'></q></dir></style></legend>
              <i id='lBi5q'><tr id='lBi5q'><dt id='lBi5q'><q id='lBi5q'><span id='lBi5q'><b id='lBi5q'><form id='lBi5q'><ins id='lBi5q'></ins><ul id='lBi5q'></ul><sub id='lBi5q'></sub></form><legend id='lBi5q'></legend><bdo id='lBi5q'><pre id='lBi5q'><center id='lBi5q'></center></pre></bdo></b><th id='lBi5q'></th></span></q></dt></tr></i><div id='lBi5q'><tfoot id='lBi5q'></tfoot><dl id='lBi5q'><fieldset id='lBi5q'></fieldset></dl></div>
                  <bdo id='lBi5q'></bdo><ul id='lBi5q'></ul>
                  本文介绍了LNK2019:未解析的外部符号 _main 在函数 ___tmainCRTStartup 中引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下错误:

                  LNK2019:未解析的外部符号 _main 在函数 ___tmainCRTStartup 中引用

                  LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

                  有很多与此错误相关的线程,但这些解决方案都不适合我.而且,没有人解释为什么会出现这个错误.

                  There are a lot of threads relating to this error, but none of those solutions worked for me. And, none explained why this error is here.

                  我试过了:

                  • wWinMainCRTStartup 作为链接器属性中的入口点 (线程)
                  • 将链接器设置为Windows"(与上面相同的线程)
                  • 右键单击解决方案名称 -> 添加 -> 现有项目 -> 带有主文件的文件(与上述相同的线程)
                  • #include (错误 LNK2019:未解析的外部符号 _main 在函数 ___tmainCRTStartup 中引用)
                  • 尝试项目 + 属性、C/C++、代码生成、缓冲区安全检查 = 否 (线程)
                  • 选项:C/C++、代码生成、运行时库=/MTd;C/C++,代码生成,基本运行时检查=默认;C/C++,代码生成,缓冲区安全检查=否;链接器,高级,入口点=main (线程)
                  • 注释掉 main.cpp 中的标头,除了 using namespace std#include - 导致级联和滚雪球错误引用这些标头的函数
                  • 我删除了main.cpp中除测试代码之外的所有内容,并排除了除main.cpp之外的所有源文件;正如预期的那样,它奏效了,所以朝着正确的方向迈出了一小步.问题必须出在头文件之一.
                  • 使用 Win32 Windows 应用程序模板创建新项目 (线程 和 thread)
                  • wWinMainCRTStartup as entry point in the linker properties (thread)
                  • set the linker to "Windows" (same thread as above)
                  • Right click on solution name->Add->Existing Item->file with main (same thread as above)
                  • #include <tchar.h> (error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup)
                  • try Project + properties, C/C++, Code generation, Buffer security check = No (thread)
                  • Options: C/C++, Code generation, Runtime library=/MTd; C/C++, Code generation, Basic Runtime Checks=default; C/C++, Code generation, Buffer security check=No; Linker, Advanced, Entry Point=main (thread)
                  • commented out headers in main.cpp except using namespace std and #include <iostream> - results in cascading and snowballing error from functions that referencing those headers
                  • I deleted everything in main.cpp except test code, and excluded all source files except main.cpp; as expected it worked, so a small step in the right direction. The problem must be with one of the header files.
                  • create new project with Win32 Windows application template (thread and thread)

                  没试过,怀疑这些也行不通:

                  Have not tried and suspect that these also will not work:

                  • 使用 int main()(不确定它们的意思,文件名或主函数名)(线程)
                  • 使用 cmake 在 Windows 7 x64 上构建(线程)
                  • use int main() (not sure what they mean, file name or main function name) (thread)
                  • using cmake to build on Windows 7 x64 (thread)

                  为什么会出现此错误,解决方法是什么?

                  Why am I getting this error, and what is the solution?

                  推荐答案

                  您的项目类型是什么?如果它是Win32 项目",则您的入口点应该是 (w)WinMain.如果它是Win32 控制台项目",那么它应该是 (w)main.名称 _tmain 被 #定义为 mainwmain 取决于是否定义了 UNICODE.

                  What is your project type? If it's a "Win32 project", your entry point should be (w)WinMain. If it's a "Win32 Console Project", then it should be (w)main. The name _tmain is #defined to be either main or wmain depending on whether UNICODE is defined or not.

                  如果是 DLL,则 DllMain.

                  If it's a DLL, then DllMain.

                  项目类型可以在项目属性、链接器、系统、子系统下看到.它会说控制台"或Windows".

                  The project type can be seen under project properties, Linker, System, Subsystem. It would say either "Console" or "Windows".

                  请注意,入口点名称取决于是否定义了 UNICODE.在 VS2008 中,它是默认定义的.

                  Note that the entry point name varies depending on whether UNICODE is defined or not. In VS2008, it's defined by default.

                  main 的正确原型是

                  The proper prototype for main is either

                  int _tmain(int argc, _TCHAR* argv[])
                  

                  int _tmain()
                  

                  确保它是其中之一.

                  如果您在 _TCHAR 上遇到错误,请放置一个

                  If you're getting an error on _TCHAR, place an

                  #include <tchar.h>
                  

                  如果您认为问题出在其中一个标题上,请使用 main() 转到文件的属性,然后在预处理器下启用预处理文件的生成.然后编译.您将获得一个扩展名为 .i 的文件.打开它,看看 main() 函数是否发生了什么令人不快的事情.理论上可能存在流氓#defines...

                  If you think the issue is with one of the headers, go to the properties of the file with main(), and under Preprocessor, enable generating of the preprocessed file. Then compile. You'll get a file with the same name a .i extension. Open it, and see if anything unsavory happened to the main() function. There can be rogue #defines in theory...

                  编辑 2:

                  定义了 UNICODE(这是默认值)后,链接器期望入口点是 wmain(),而不是 main()._tmain 具有与 UNICODE 无关的优势 - 它可以转换为 main 或 wmain.

                  With UNICODE defined (which is the default), the linker expects the entry point to be wmain(), not main(). _tmain has the advantage of being UNICODE-agnostic - it translates to either main or wmain.

                  前段时间,有理由同时维护 ANSI 版本和 Unicode 版本.Windows 95/98/Me 中的 Unicode 支持非常不完整.主要的 API 是 ANSI,Unicode 版本随处可见,但并不普遍.此外,VS 调试器无法显示 Unicode 字符串.在 NT 内核操作系统(即 Windows 2000/XP/Vista/7/8/10)中,Unicode 支持是主要的,ANSI 函数被添加到顶部.所以从 VS2005 开始,项目创建时的默认值是 Unicode.这意味着 - wmain.由于参数类型不同,它们无法保持相同的入口点名称._TCHAR #defined 为 char 或 wchar_t.所以 _tmain 要么是 main(int argc, char **argv) 要么 wmain(int argc, wchar_t **argv).

                  Some time ago, there was a reason to maintain both an ANSI build and a Unicode build. Unicode support was sorely incomplete in Windows 95/98/Me. The primary APIs were ANSI, and Unicode versions existed here and there, but not pervasively. Also, the VS debugger had trouble displaying Unicode strings. In the NT kernel OSes (that's Windows 2000/XP/Vista/7/8/10), Unicode support is primary, and ANSI functions are added on top. So ever since VS2005, the default upon project creation is Unicode. That means - wmain. They could not keep the same entry point name because the parameter types are different. _TCHAR is #defined to be either char or wchar_t. So _tmain is either main(int argc, char **argv) or wmain(int argc, wchar_t **argv).

                  您在某个时候在 _tmain 处遇到错误的原因可能是因为您没有将 argv 的类型更改为 _TCHAR**.

                  The reason you were getting an error at _tmain at some point was probably because you did not change the type of argv to _TCHAR**.

                  如果您不打算支持 ANSI(可能不支持),您可以将入口点重新表述为

                  If you're not planning to ever support ANSI (probably not), you can reformulate your entry point as

                  int wmain(int argc, wchar_t *argv[])
                  

                  并删除 tchar.h 包含行.

                  这篇关于LNK2019:未解析的外部符号 _main 在函数 ___tmainCRTStartup 中引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Visual Studio 2008、C++ 的探查器? 下一篇:将库添加到 Visual Studio 2008 C++ 项目

                  相关文章

                    <bdo id='j2eqw'></bdo><ul id='j2eqw'></ul>

                    <legend id='j2eqw'><style id='j2eqw'><dir id='j2eqw'><q id='j2eqw'></q></dir></style></legend>
                  1. <i id='j2eqw'><tr id='j2eqw'><dt id='j2eqw'><q id='j2eqw'><span id='j2eqw'><b id='j2eqw'><form id='j2eqw'><ins id='j2eqw'></ins><ul id='j2eqw'></ul><sub id='j2eqw'></sub></form><legend id='j2eqw'></legend><bdo id='j2eqw'><pre id='j2eqw'><center id='j2eqw'></center></pre></bdo></b><th id='j2eqw'></th></span></q></dt></tr></i><div id='j2eqw'><tfoot id='j2eqw'></tfoot><dl id='j2eqw'><fieldset id='j2eqw'></fieldset></dl></div>

                    <small id='j2eqw'></small><noframes id='j2eqw'>

                    1. <tfoot id='j2eqw'></tfoot>