VS异常问题——Solution

本文介绍了如何解决VS2005中出现的“没有找到MSVCR80.dll”及LNK2019错误问题。通过在stdafx.h文件中添加特定代码解决DLL缺失问题,并调整项目属性设置解决LNK2019错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、没有找到MSVCR80.DLL 

//出现的现象是在debug的时候出现了"没有找到MSVCR80.dll "的对话框;但是在Release中没有报错!
在stdafx.h 文件中添加以下代码
#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='X86' publicKeyToken='1fc8b3b9a1e18e3b' language='*'\"")

在VS2005中,如果没有上面这行代码,运行会提示:没有找到 MSVCR80.dll

二、mtd.lib(xdebug.obj) : error LNK2019: 无法解析的外部符号 unresolved external symbol __malloc_dbg

今天上午在VC2005中调试一个可执行文件时代码生成通过,但是 连接时编译器报错

1>Linking...
1>   Creating library D:\Visual Studio 2008\test\Debug\test.lib and object D:\Visual Studio 2008\test\Debug\test.exp
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
1>libcpmtd.lib(stdthrow.obj) : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z)
1>D:\Visual Studio 2008\test\Debug\test.dll : fatal error LNK1120: 3 unresolved externals
1>Build log was saved at "file://d:\Visual Studio 2008\test\test\Debug\BuildLog.htm"
1>test - 4 error(s), 4 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 正在链接...
LINK : warning LNK4098: 默认库“LIBCMT”与其他库的使用冲突;请使用 /NODEFAULTLIB:library
libcpmtd.lib(cerr.obj) : error LNK2001: 无法解析的外部符号 __CrtDbgReportW
libcpmtd.lib(stdthrow.obj) : error LNK2001: 无法解析的外部符号 __CrtDbgReportW
libcpmtd.lib(xmbtowc.obj) : error LNK2001: 无法解析的外部符号 __CrtDbgReportW
libcpmtd.lib(cout.obj) : error LNK2001: 无法解析的外部符号 __CrtDbgReportW
libcpmtd.lib(xdebug.obj) : error LNK2019: 无法解析的外部符号 __malloc_dbg,该符号在函数 "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z) 中被引用
libcpmtd.lib(xmbtowc.obj) : error LNK2001: 无法解析的外部符号 __malloc_dbg
libcpmtd.lib(xdebug.obj) : error LNK2019: 无法解析的外部符号 __free_dbg,该符号在函数 "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z) 中被引用
libcpmtd.lib(xmbtowc.obj) : error LNK2001: 无法解析的外部符号 __free_dbg
libcpmtd.lib(_tolower.obj) : error LNK2019: 无法解析的外部符号 __calloc_dbg,该符号在函数 __Getctype 中被引用

 
后来发现是单线程/多线程的问题,描述如下
运行时库现在包含可防止混合不同类型的指令。如果试图在同一个程序中使用不同类型的运行时库或使用调试和非调试版本的运行时库,则将收到此警告。例如,如果编译一个文件以使用一种运行时库,而编译另一个文件以使用另一种运行时库(例如单线程运行时库对多线程运行时库),并试图链接它们,则将得到此警告。应将所有源文件编译为使用同一个运行时库。有关更多信息,请参见使用运行时库(/MD、/MT 和 /LD)编译器选项。
 
  解决方案
于是打开项目属性,在“配置属性-->C/C++-->代码生成-->运行时库”中将“多线程(/MT)”修改为“多线程调试(/MTd)”,
或者Project -> ** Properties-> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library  -> Multi-threaded (/MT)  改为 Multi-threaded Debug (/MTd)
 
再重新调试一下,问题解决。




### 关于 `solution` 函数 在提供的参考资料中并未直接提及 `solution` 函数的具体定义或使用场景。然而,在编程实践中,通常会遇到各种自定义的 `solution` 函数用于解决问题或是作为竞赛平台上的解法提交接口。下面基于常见实践提供一种可能的解释以及如何构建这样一个通用解决方案函数。 #### 定义与用途 `solution` 函数一般是指用来解决特定问题的核心逻辑封装体。它接受输入参数并返回处理后的结果。具体到不同应用场景下,其内部实现会有很大差异。为了更好地理解这个概念,这里展示了一个简单的 Python 版本例子,假设目标是从给定列表中找到最大值: ```python def solution(nums): """ 找出列表中的最大数值 参数: nums (list): 整数类型的列表 返回: int: 列表中的最大整数值 """ if not nums: raise ValueError("List cannot be empty") max_num = float('-inf') for num in nums: if num > max_num: max_num = num return max_num ``` 此版本的 `solution` 接收一个名为 `nums` 的列表作为参数,并通过遍历寻找其中的最大值。如果传入的是空列表,则抛出异常提示错误[^1]。 #### 示例代码 考虑到上述描述较为抽象,以下是另一个更具体的案例——计算斐波那契序列第 n 项的方法之一: ```python def fibonacci(n, memo={}): """ 计算斐波那契数列的第n项 """ if n <= 0: return "Input should be positive integer" elif n == 1 or n == 2: return 1 if n not in memo: memo[n] = fibonacci(n-1) + fibonacci(n-2) return memo[n] # 将fibonacci函数重命名为solution以便演示 solution = fibonacci print(solution(9)) # 输出:34 ``` 在这个实例里,`solution` 被重新指向了实现了动态规划算法求解斐波那契数列的功能函数 `fibonacci` 。这展示了当面对不同的实际需求时,可以灵活调整 `solution` 函数的内容以适应具体情况的需求[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值