首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用/MTd设置而不是/MDd重新构建库时出现LINK2019错误

使用/MTd设置而不是/MDd重新构建库时出现LINK2019错误
EN

Stack Overflow用户
提问于 2021-07-27 04:39:12
回答 1查看 29关注 0票数 0

我知道它已经被详细讨论过很多次了,但我的案例有一些特殊的情况,我不知道如何正确地解决。

带有/MDd解决方案的库构建正常。但它不是应用程序所需要的,因为它需要/MT(d)版本。

现在,我已经将编译器选项更改为/MTd,解决了一些外部项目的依赖关系,但仍然得到了以下结果:

代码语言:javascript
复制
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.obj

log.h就是这样的:

代码语言:javascript
复制
#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_H

log.cpp

代码语言:javascript
复制
#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 hooks

hooks.h

代码语言:javascript
复制
#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_H

hooks.cpp

代码语言:javascript
复制
#include "hooks.h"


namespace hooks {

Hooks getHooks()
{
Hooks hooks;  
return hooks;
}

Hooks getVftableHooks()
{
Hooks hooks;
return hooks;
}

} // namespace hooks

有没有办法解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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版本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68536091

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档