0
votes

So i have multiple files in my little program, what is happening is i am getting link2001 errors between one of my header files and cpp files.

struct startup
{
    static std::string latestVersion;
    static std::string currentVersion;
    static std::string latestUpdate;
    static bool upToDate;
    static void checkUpToDate();
    static void consoleStartup();

};

That is my header file and here is my cpp file:

    #include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>

void startup::checkUpToDate()
{
    if (startup::currentVersion == startup::latestVersion)
    {
        startup::upToDate = true;
    }
    if (startup::currentVersion != startup::latestVersion)
    {
        startup::upToDate = false;
    }
}
void startup::consoleStartup()
{
    startup::checkUpToDate();
    HANDLE hConsole;
    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    FlushConsoleInputBuffer(hConsole);
    SetConsoleTextAttribute(hConsole, color::red);
    std::cout << R"(
         _,.-------.,_
     ,;~'             '~;,
   ,;                     ;,
  ;                         ;
 ,'                         ',
,;                           ;,
; ;      .           .      ; ;
| ;   ______       ______   ; |
|  `/~"     ~" . "~     "~\'  |
|  ~  ,-~~~^~, | ,~^~~~-,  ~  |
 |   |        }:{        |   |
 |   l       / | \       !   |
 .~  (__,.--" .^. "--.,__)  ~.
 |     ---;' / | \ `;---     |
  \__.       \/^\/       .__/
   V| \                 / |V
    | |T~\___!___!___/~T| |
    | |`IIII_I_I_I_IIII'| |
    |  \,III I I I III,/  |
     \   `~~~~~~~~~~'    /
       \   .       .   /     
         \.    ^    ./
)" << std::endl;

    SetConsoleTextAttribute(hConsole, color::green);
    std::cout << "---------------------The ----------------------" << std::endl;
    SetConsoleTextAttribute(hConsole, color::purple);
    if (startup::upToDate == true)
    {
        std::cout << "      [You are all up to date! Your version: " + startup::currentVersion + " Latest version: " + startup::latestVersion + "]" << std::endl;
    }
    else if (startup::upToDate == false)
    {
        std::cout << "      [You are running on a old update! Your version: " + startup::currentVersion + " Latest version: " + startup::latestVersion + "]" << std::endl;
    }
    SetConsoleTextAttribute(hConsole, color::white);
}

Everything worked fine before i moved it to separate file and had everything in main.cpp. I am not 100% certain what i am doing wrong although i know what i link2001 error is i can't seem to be able to fix it.

My code may also be very bad, im still learning, thanks in advance :)

Also here is the error message:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2001 unresolved external symbol "public: static bool startup::upToDate" (?upToDate@startup@@2_NA)    FileEncryptionDecryptions   C:\Users\Jonitoi\Desktop\Projects\Visual Studio\cpp\FileEncryptionDecryptions\FileEncryptionDecryptions\startup.obj 1   
1
That ASCII skull tho - MechMK1
You should post the full error message - Asesh
When posting questions about build errors, always copy (as text) the complete and full output, and paste it (without modifications) into the question body. Please take some time to read about how to ask good questions. - Some programmer dude
upToDate is a static member variable. You should initialize it at global scope - Asesh

1 Answers

0
votes

upToDate is a static member variable so you should initialize it at global scope:

struct startup
{
    static std::string latestVersion;
    static std::string currentVersion;
    static std::string latestUpdate;
    static bool upToDate;
    static void checkUpToDate();
    static void consoleStartup();
};

bool startup::upToDate = false;