visual studios express 2013 errors

visual studios express 2013 errors

本文关键字:errors 2013 express studios visual      更新时间:2023-10-16
每次

我制作新程序时都会在编译时出现此错误,以前我使用 2012 并且从未遇到过这个问题,但现在我每次都看到这个:

错误:

Error   2   error LNK2019: unresolved external symbol 
"public: __cdecl lonework::App::App(void)" (??0App@lonework@@Q$AAA@XZ)
referenced in function "public: void __thiscall <lambda_b6bf150325cab1ba448790bcac21fea0>::operator()(class Windows::UI::Xaml::ApplicationInitializationCallbackParams ^)
const " (??R<lambda_b6bf150325cab1ba448790bcac21fea0>@@QBEXP$AAVApplicationInitializationCallbackParams@Xaml@UI@Windows@@@Z)    C:UsersLoganDocumentsVisual Studio 
    2013Projectsloneworkloneworklonework.WindowsXamlTypeInfo.g.obj lonework.Windows

当前处理的代码:

#include <pch.h>
#include <conio.h>
#include <stdio.h>
#include <Windows.h>
int yes();
int no();
int main()
{
    char choice;
    printf("Think of a number between one and tenn");
    Sleep(2000);
    printf("Got it yet?n Y/N ");
    scanf_s("%c", &choice,1);
    if (choice == 'y' || choice == 'Y')
    {
        printf("That's good");
        yes();
    }
    else if (choice == 'n' || choice == 'N')
    {
        printf("Are you really that slow");
        no();
    }
    getchar();
    return 0;
}
int yes()
{
    printf("Good for you, keep thinking about it...n");
    printf("Now think of another one, a different onen Got it?n I'll assume yes, sounds good.n     Now I'll tell you your number.n");
    printf("...n");
    Sleep(2000);
    printf("...n");
    Sleep(2000);
    printf("Ahem, 3 and 7");
    return 0;
}
int no()
{
    printf("Alright, back to the top.n");
    main();
    return 0;
}

请确保在创建新项目时选择空项目或C++控制台应用程序,而不是托管C++应用程序。

对于此代码,您无需include pch.h,实际上VS没有附带此类文件。

有两种方法可以纠正此问题

1.) 在 VS 中单击

  1. 为项目命名
  2. 创建一个新的C++项目,
  3. 选择Win32 Application
  4. 取消选中precompiled header
  5. 取消选中Security Development Lifecycle (SDL) checks
  6. 单击完成
  7. 将创建一个新项目,并将打开带有您的项目名称的 cpp 文件。
  8. 复制并粘贴此源代码并删除行#include <pch.h>现在您可以编译并运行它。

2.)在包含此项目的VS解决方案中:

  1. 右键单击解决方案资源管理器中的项目名称

  2. 单击Properties单击左侧的C/C++选项卡

  3. 单击"预编译标头"

  4. 在列Precompiled headers右侧,从use更改为Not Using Precompiled Headers

  5. 点击应用图标

  6. 现在,如果您使用的是Visual Studio Community,您将拥有一个文件名为" AssemblyInfo ",右键单击该文件并将其删除,然后选择"删除"

  7. 现在删除第一行#include <pch.h>

    编译并运行它

实际上您正在用Visual C++编译C代码,因此,当您创建新项目时,您必须取消选中SDL检查(安全开发生命周期)

另一种简单的方法是创建一个新的blank C++ project,在解决方案资源管理器上右键单击source files。 单击add,单击new item,选择C++ File,现在将代码粘贴在其中并运行它。如果您正在开始新项目,这是最简单的方法。