我遇到問題。我收到一個錯誤,我不確定它爲什麼會發生。無法解析的外部符號問題
2>Home.obj : error LNK2019: unresolved external symbol "**void __cdecl LogAString(char *,...)**" ([email protected]@YAXPADZZ) referenced in function "**public: static void __cdecl X::Home::HomeStart(void)**" ([email protected]@[email protected]@SAXXZ)
2>Widget.obj : error LNK2001: unresolved external symbol "void __cdecl LogAString(char *,...)" ([email protected]@YAXPADZZ)
2>J:\src\out.dll : fatal error LNK1120: 1 unresolved externals
這裏是我的代碼:
Log.h
#pragma once
#include <iostream>
#include <cstdarg>
void LogAString(char* fmt, ...);
void LogAnError(char* fmt, ...);
Log.cpp
#include "Log.h"
#include <Util/String/String Formatting.h> // defines format(). Does not have any errors or issues.
void LogAString(char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
};
void LogAnError(char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
auto formatted_string = format("ERROR: %s", fmt).c_str();
LogAString(const_cast<char*>(formatted_string), ap);
va_end(ap);
};
Home.cpp(摘錄)
#include "Home.h"
#include "Log.h"
namespace X {
void Home::HomeStart()
{
while (true)
{
auto number_of_widgets = Widgets::Count();
LogAString("Loading with %d widgets", number_of_widgets);
}
}
} // namespace X
我以爲我已經分別在頭文件和cpp文件中聲明和定義了函數。爲什麼我會收到這些錯誤?我現在已經呆了幾個小時了,但仍不確定爲什麼會發生這種情況。在VS 2010上使用VC++。
我現在沒有使用任何其他外部庫。編譯目標是一個DLL,「out.dll」。
這是日誌的東西在一個單獨的項目? – FailedDev
@FaileDev,它在同一個項目中。 – Yuki
事實上,我編譯你的代碼並執行它,它運行良好。所以,你要麼有兩個項目,要麼正在發生一些神奇的事情。 – FailedDev