Visual Studio 2019 拒绝构建解决方案 C++

吉姆

出于某种原因,Visual Studio 突然拒绝构建我的 C++ 文件。此外,当它弹出“存在构建错误,您想继续上次成功构建吗”时,我按是,然后说无法启动程序。我正在运行带有最新更新的 Windows 10 和带有最新更新的 Visual Studio 2019。

当它说无法启动程序时会发生什么:

在此处输入图片说明

这是我的构建输出显示的内容: 编辑:这是我删除所有变量副本并梳理所有以前的错误后的新版本:

1>------ Build started: Project: MasterApp, Configuration: Debug Win32 ------
1>MasterApp.cpp

1>C:\Users\foo\source\repos\MasterApp\MasterApp.cpp(33,15): warning C4244: 
'argument': conversion from 'time_t' to 'unsigned int', possible loss of data

1>masterappRef.cpp

1>Generating Code...

1>masterappRef.obj : error LNK2005: "double version" ([email protected]@3NA) already 
defined in MasterApp.obj

1>C:\Users\foo\source\repos\MasterApp\Debug\MasterApp.exe : fatal error LNK1169: one or more multiply defined symbols found

1>Done building project "MasterApp.vcxproj" -- FAILED

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

代码如下:


#pragma comment(lib, "winmm.lib")
// MasterApp.cpp : This file contains the 'main' function. Program execution begins and ends there.


#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <time.h>
#include "MasterAppRef.h"
#include <stdlib.h>
using namespace std;

//global variables
string passwd_admin = "admin";
string PassEntered;
string Username1 = "admin";
string Username2 = "administrator";
string UserEntered;
double version = 2.4;







int main()
{

    //setting console window title
    SetConsoleTitle ( TEXT("Master App"));
    //seed for the randomiser
    srand(time(NULL));

    //declaring variable
    int randomDice;
    system("cls");

    cout << "Please login\n";
    cout << "\n";

    cout << "Enter Username: ";
    cin >> UserEntered;
    if (UserEntered == Username1) {

    }
    else if (UserEntered == Username2) {

    }
    else if (UserEntered != Username2 && UserEntered != Username1) {
        return 0;
    }
    else {
        return 0;
    }

    system("cls");
    cout << "Please login\n\n";
    cout << "Enter Password: ";
    cin >> PassEntered;

    if (PassEntered == passwd_admin) {
        cout << "\nAccess Granted!\n\n\n";
    }
    else {
        cout << "Wrong Password";
        return 0;

    }
    system("cls");

    cout << "\n\n                                                     [  Starting  ]\n";
    cout << "                                                Press enter to continue";

    system("pause >nul");
    system("cls");
    Sleep(2200);

    cout << "\n\n\nMaster App " << version << " 2020\n\n";
    Sleep(1530);

    bool played = PlaySound(TEXT("C:\\foo\\startup.wav"), NULL, SND_ASYNC);
    Sleep(3000);
    int choice;
    system("cls");


    cout << "\nMaster App                                                           Version " << version << "\n\n";

    cout << "Choose and option and then press enter\n";
    cout << "(E.g. 1 [PRESS ENTER] will give you choice number 1)\n\n";

    cout << "1) Close App\n";
    cout << "2) Roll the Dice\n";
    cout << "3) Pull up some ASCII art\n";
    cout << "4) Give me a random number\n";
    cout << "5) Give me some insparation\n";
    cout << "6) Open Administrator Panel\n";
    cout << "7) Play music\n";
    cout << "8) Open Command Prompt\n";
    cout << "9) See Change Log\n";
    cout << "10) Open Calculator\n";
    cout << "11) Open New Notepad\n";
    cout << "12) Clock\n";
    cout << "13) Ask the magical 8 ball\n";

    cout << "\n\nYour choice: ";
    cin >> choice;

    if (choice == 1) {
        return 0;
    }
    else if (choice == 2) {

        randomDice = rand() % 6 + 1;
        cout << "\n "<<"And your dice has rolled... " << randomDice <<"!\n";
        system("pause");
    }
    else if (choice == 3) {
        //This is the only ascii art that doesn't have backslashes.
        cout << " _______  _______  _______  ___   ___     _______  ______    _______  __  \n";
        cout << "|   _   ||       ||       ||   | |   |   |   _   ||    _ |  |       ||  |\n";
        cout << "|  |_|  ||  _____||       ||   | |   |   |  |_|  ||   | ||  |_     _||  | \n";
        cout << "|       || |_____ |       ||   | |   |   |       ||   |_||_   |   |  |  |\n";
        cout << "|       ||_____  ||      _||   | |   |   |       ||    __  |  |   |  |__| \n";
        cout << "|   _   | _____| ||     |_ |   | |   |   |   _   ||   |  | |  |   |   __ \n";
        cout << "|__| |__||_______||_______||___| |___|   |__| |__||___|  |_|  |___|  |__| \n";
        system("pause");
    }
    else if (choice == 4) {
        int randomNumber;

        randomNumber = rand() % 10000 + 1;
        cout << "\n " << "Your random number is: " << randomNumber << "\n";
        system("pause");

    }
    else if (choice == 5) {
        int inspNum;
        inspNum = rand() % 6 + 1;
        if (inspNum == 6) {
            cout << "Life is like riding a bicycle. To keep your balance, you must keep moving.\n";
            system("pause");
        }
        else if (inspNum == 5) {
            cout << "Those who think they are dumb are actually the smart ones...\n";
            system("pause");
        }
        else if (inspNum == 4) {
            cout << "Act like what you're doing matters - It does.\n";
            system("pause");
        }
        else if (inspNum == 3) {
            //By Albert Einstein
            cout << "Success is not final, failure is not fatal: it is the courage to continue that counts.\n";
            system("pause");
        }
        else if (inspNum == 2) {
            cout << "Never bend your head. Always hold it high. Look the world straight in the eye.\n";
            system("pause");
        }
        else if (inspNum == 1) {
            cout << "What you get by achieving your goals is not as important as what you become by achieving your goals.\n";
            system("pause");
        }
        else {
            cout << "Error!\n";
            system("pause");
            return 0;
        }
    }else if (choice == 6) {

        system("cls");
        string adminName = "Administrator";
        string adminPass = "administrator";
        string iu;
        string ip;




        cout << "Enter Administrator Username: ";
        cin >> iu;
        if (iu == adminName) {
            cout << "Enter Password: ";
            cin >> ip;
            if (ip == adminPass) {
                cout << "Access Granted! You may proceed now.\n\n";
                system("pause");
            }
            else {
                cout << "Incorrect Password!\n";
                system("pause");
                return 0;
            }
        }
        else {
            cout << "Incorect Username!\n";
                system("pause");
                return 0;
        }
        system("cls");
        cout << "Administrator Panel\n\n";


        int adminChoice;


        cout << "Options:\n";
        cout << "1) See Change Log\n";
        cout << "2) Close App\n";
        cout << "3) Change Colour\n";
        cin >> adminChoice;


        if (adminChoice == 1) {
            system("cls");
            cout << "Change Log\n\n";

            cout << "Version " << version << "\n\n";

            cout << "1) More options\n";
            cout << "2) Added more music and credited music artists/websites\n";
            cout << "3) Administrator panel discontinued - slowly migrating to main panel\n";
            cout << "4) Added something new...\n";



        }
        else if (adminChoice == 2) {
            system("cls");
            cout << "Closing...";
            Sleep(3000);
            return 0;
        }
        else if (adminChoice == 3) {
            cout << "Switch Colour to...\n\n";

            cout << "1) Default\n";
            cout << "2) High Contrast\n";
            int colourChoice = 1;
            cin >> colourChoice;
            if (colourChoice == 1) {
                system("color");
                system("cls");
                system("pause");
            }
            else if (colourChoice == 2) {
                system("color fc");
                system("pause <nul");

            }
        }


    }

    else if (choice == 7) {
    system("cls");

    cout << "Choose a song to play:\n\n";

    cout << "Sample Music\n\n";

    cout << "1) Beethoven's 9th Symphony (11:48)\n";
    cout << "2) Beethoven's 1st Symphony (26:12)\n";
    cout << "\nUpbeat Music\n\n";

    cout << "3) Piano Piece (2:02)\n";
    cout << "\nMore coming soon!\n";
    int song;
    cin >> song;
    if (song == 1) {
        system("cls");
        cout << "\nPLaying: Beethoven's 9th Symphony\n\n";
        PlaySound(TEXT("C:\\foo\\beethoven.wav"), NULL, SND_ASYNC);
        cout << "\n\n\nPress any key to stop playing\n";
        system("pause >nul");
    }
    else if (song == 2) {
        system("cls");
        cout << "\nPlaying: Beethoven's 1st Symphony\n\n";
        PlaySound(TEXT("C:\\foo\\beethoven1.wav"), NULL, SND_ASYNC);
        cout << "\n\n\nPress any key to stop playing\n";
        system("pause >nul");
    }
    else if (song == 3) {
        system("cls");
        cout << "\nPlaying: Upbeat Piano Piece\n\n";
        PlaySound(TEXT("C:\\foo\\upbeatpiano.wav"), NULL, SND_ASYNC);
        cout << "\n\n\nPress any key to stop playing\n";
        system("pause >nul");
    }


    }
    else if (choice == 8) {
    system("cmd.exe");
    system("cd C:\\Windows\\System32");
    system("pause >nul");
    }
    else if (choice == 9) {
    void versionInfo();
    }
    else if (choice == 10) {
    system("cls");
    system("calc.exe");
    cout << "Opening Calculator...\n";
    system("pause >nul");
    }
    else if (choice == 11) {
    system("notepad");
    }
    else if (choice == 12) {
    system("cls");
    system("date /t");
    cout << "\n";
    system("time /t");
    cout << "\n";
    cout << "\n";
    system("pause");
    }
    else if (choice == 13) {
    system("cls");
    int eightBall;
    eightBall = rand() % 6 + 1;
    cout << "Ask the magical eight-ball a question! Press enter when you have it...";
    system("pause >nul");
    system("cls");
    if (eightBall == 1) {
        cout << "Think harder and try again...\n";
        system("pause");
        void eightBallFunction();
    }
    else if (eightBall == 2) {
        cout << "Seems like a good idea\n";
        system("pause");
        void eightBallFunction();
    }
    else if (eightBall == 3) {
        cout << "No, don't.\n";
        system("pause");
        void eightBallFunction();
    }
    else if (eightBall == 4) {
        cout << "YAAAAASSS!\n";
        system("pause");
        void eightBallFunction();
    }
    else if (eightBall == 5) {
        cout << "Hmm... I didn't get that. Try again.\n";
        system("pause");
        void eightBallFunction();
    }
    else if (eightBall == 6) {
        cout << "Um, sure\n";
        system("pause");
        void eightBallFunction();
    }
    else if (eightBall == 7) {
        cout << "It's up to you, but I would say no.\n";
        system("pause");
        void eightBallFunction();

    }
    else if (eightBall == 8) {
        cout << "Well, I would think that you shouldn't\n";
        system("pause");
        void eightBallFunction();
    }
    }
    else if (choice == 14) {

    system("cls");


    }




}



MasterAppRef.h:

#pragma once
#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <time.h>
#include <stdlib.h>
using namespace std;






int main();
//declaring functions
void versionInfo();
void eightBallFunction();

MasterAppRef.cpp:

#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <time.h>
#include "MasterAppRef.h"
#include <stdlib.h>
using namespace std;
double version;


}
void eightBallFunction() {
    system("cls");
    int TryeightBall;
    TryeightBall = rand() % 6 + 1;
    cout << "Ask the magical eight-ball a question! Press enter when you have it...";
    system("pause >nul");
    system("cls");
    if (TryeightBall == 1) {
        cout << "Think harder and try again...\n";
        system("pause");
        void eightBallFunction();
    }
    else if (TryeightBall == 2) {
        cout << "Seems like a good idea\n";
        system("pause");
        void eightBallFunction();
    }
    else if (TryeightBall == 3) {
        cout << "No, don't.\n";
        system("pause");
        void eightBallFunction();
    }
    else if (TryeightBall == 4) {
        cout << "YAAAAASSS!\n";
        system("pause");
        void eightBallFunction();
    }
    else if (TryeightBall == 5) {
        cout << "Hmm... I didn't get that. Try again.\n";
        system("pause");
        void eightBallFunction();
    }
    else if (TryeightBall == 6) {
        cout << "Um, sure\n";
        system("pause");
        void eightBallFunction();
    }
    else if (TryeightBall == 7) {
        cout << "It's up to you, but I would say no.\n";
        system("pause");
        void eightBallFunction();

    }
}

任何帮助将不胜感激!

克里斯MM

在您提供的第一个代码块中,您有

double version = 2.4;

在 MasterAppRef.cpp 中,你有

double version;

因此,您对 有两个定义version如果这些应该引用相同的变量,那么在单个头文件中,您将放置:

extern double version;

然后两个 .cpp 文件都将包含该头文件。只有一个 .cpp 文件会有定义(例如,您的第一个块)。如果它们应该引用不同的变量,那么您有两种选择。一,将它们重命名为具有唯一名称。或两个,将它们放在匿名命名空间中。IE

namespace {
    double version;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Visual Studio 2019在保存时禁用自动构建解决方案

解决方案文件 Visual Studio 2019 中的路径已更改,现在无法构建文件

Visual Studio 2019开放解决方案文件不兼容

Visual Studio构建解决方案

在多平台解决方案中构建 Visual Studio C++ 项目

Visual Studio 2019 C ++ CodeLens

Visual Studio 2019 编译构建

解决方案探索中的区域选项不会在Visual Studio 2019中显示

在Visual Studio 2019中,是否可以在解决方案文件之外配置项目路径?

在Visual Studio Community 2019解决方案中成功初始化XAudio2

如何在Visual Studio 2019中更新.sln(解决方案)文件

如何在Visual Studio 2019中从其他解决方案链接`.lib`库?

Visual Studio 2019在.Net Core 3.1解决方案中创建.NetStandard 2.0.3库而不是2.1

无法在 Visual Studio 2019 中打开解决方案的属性

C ++中的Visual Studio解决方案配置值

无需DLL的Visual Studio托管C ++的编译解决方案

使用Visual Studio 2019 C#的gRPC构建错误

Visual Studio 2015 中的构建解决方案给出错误“生成 Win32 资源时出错:访问被拒绝”

在Visual Studio解决方案中仅构建特定项目

如何在Linux下构建Visual Studio解决方案?

如何使Visual Studio使用FAKE构建我的解决方案?

Visual Studio:构建解决方案时输出时间戳

Visual Studio在启动时自动构建解决方案

生成解决方案时如何解决Visual Studio 2019'无效配置文件ms_6_5'错误?

Visual Studio 2019/C++ 錯誤?

为什么我的 Visual Studio 2019 解决方案打开时解决方案资源管理器关闭?

如何使用Visual Studio 2019在解决方案中为多个项目指定自定义代码分析规则集?

MSBuildWorkspace:解决方案在Visual Studio 2019上不包含任何文档并且没有任何项目

Visual Studio 2019-使用PowerShell打开文件而不是解决方案资源管理器