我知道它已经被详细讨论过很多次了,但我的案例有一些特殊的情况,我不知道如何正确地解决。
带有/MDd解决方案的库构建正常。但它不是应用程序所需要的,因为它需要/MT(d)版本。
现在,我已经将编译器选项更改为/MTd,解决了一些外部项目的依赖关系,但仍然得到了以下结果:
Error LNK2019 unresolved external symbol "bool __cdecl std::uncaught_exception(void)" (?uncaught_exception@std@@YA_NXZ) referenced in function "public: __cdecl std::basic_ostream<char,struct std::char_traits<char> >::sentry::~sentry(void)" (??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@XZ) vcruntime140 ..\vcruntime140 ..\vcruntime140\log.objlog.h就是这样的:
#ifndef LOG_H
#define LOG_H
#include <string>
namespace hooks {
/** Prints message to the file only if debug mode setting is enabled. */
void logDebug(const std::string& logFile, const std::string& message);
/** Prints message to the file. */
void logError(const std::string& logFile, const std::string& message);
} // namespace hooks
#endif // LOG_Hlog.cpp
#include "log.h"
#include <chrono>
#include <ctime>
#include <fstream>
#include <iomanip>
namespace hooks {
static void logAction(const std::string& logFile, const std::string& message)
{
using namespace std::chrono;
std::ofstream file(logFile.c_str(), std::ios_base::app);
const std::time_t time{std::time(nullptr)};
const std::tm tm = *std::localtime(&time);
file << "[" << std::put_time(&tm, "%c") << "] " << message << "\n";
}
void logDebug(const std::string& logFile, const std::string& message)
{
logAction(logFile, message);
}
void logError(const std::string& logFile, const std::string& message)
{
logAction(logFile, message);
}
} // namespace hookshooks.h
#ifndef HOOKS_H
#define HOOKS_H
#include <string>
#include <utility>
#include <vector>
namespace hooks {
using HookInfo = std::pair<void**, void*>;
using Hooks = std::vector<HookInfo>;
/** Returns array of hooks to setup. */
Hooks getHooks();
Hooks getVftableHooks();
} // namespace hooks
#endif // HOOKS_Hhooks.cpp
#include "hooks.h"
namespace hooks {
Hooks getHooks()
{
Hooks hooks;
return hooks;
}
Hooks getVftableHooks()
{
Hooks hooks;
return hooks;
}
} // namespace hooks有没有办法解决这个问题?
发布于 2021-07-29 19:30:29
找到解决方案后,剩下的唯一问题实际上与上面的问题无关。上述错误可通过以下方式解决:
在附加的库链接中添加MSVCPRTD.LIB似乎可以消除LINK2019的问题。
问题发生的原因是该库中定义的一些标准库函数没有加载。我通过检查错误消息和谷歌搜索缺少哪些函数定义以及它们属于哪个库来意识到这一点。
但根据微软文档:https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-160,现在MSVCPRTD.LIB出现了问题,因为它是一个动态的库,而不是一个静态库
MSVCPRTD.LIB的问题可以通过加载libcmtd.lib来解决,它是同一个库的/MTd版本。
https://stackoverflow.com/questions/68536091
复制相似问题