【发布时间】:2017-12-23 11:28:19
【问题描述】:
所以我的小程序中有多个文件,发生的事情是我的一个头文件和 cpp 文件之间出现了 link2001 错误。
struct startup
{
static std::string latestVersion;
static std::string currentVersion;
static std::string latestUpdate;
static bool upToDate;
static void checkUpToDate();
static void consoleStartup();
};
这是我的头文件,这是我的 cpp 文件:
#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);
}
在我将它移动到单独的文件并在 main.cpp 中包含所有内容之前,一切正常。我不是 100% 确定我做错了什么,尽管我知道我的 link2001 错误是我似乎无法修复它。
我的代码也可能很糟糕,我还在学习,提前谢谢:)
这里还有错误信息:
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
【问题讨论】:
-
那个 ASCII 骷髅头
-
你应该发布完整的错误信息
-
发布有关构建错误的问题时,请始终复制(作为文本)完整和完整的输出,并将其粘贴(不加修改)到问题正文中。请花一些时间到read about how to ask good questions。
-
upToDate是一个静态成员变量。你应该在全局范围内初始化它
标签: c++ linker-errors