VS2005 编译环境,解决 Runtime Error(运行时错误): R6034。

问题:Runtime Error R6034
在VS2005编译环境下,用makefile编译的程序爆出了一个可恶的Runtime Error。
错误如下图:

提示信息是:
Runtime Error!
R6034
An application has made an attempt to load the C runtime library incorrectly. Please contact the application’s support team for more information.
无法正常载入 C runtime library。

问题追因
程序生成之后直接执行是没有问题的,而打包后的程序却有问题,看来应该是缺少了什么文件。于是我对编译程序生成的文件一个个删除,并查看检查程序的运行情况。在$(APP).exe.manifest被文件删除之后,R6034现身了,看来罪魁祸首就是它了。
我又在MSDN上搜索R6034,得到了这个Error描述的:

C Run-Time Error R6034
Error Message

An application has made an attempt to load the C runtime library without using a manifest. This is an unsupported way to load Visual C++ DLLs. You need to modify your application to build with a manifest.

这么以来更确认了出现这个问题的原因:缺少了manifest,程序因此无法正常载入C runtime library。

解决办法
解决方法有两个:

  1. 将编译得到的 $(APP).exe.manifest 一并打包,即和应用程序放在同一个文件夹下;
  2. 将manifest文件直接嵌入到可执行文件。

嵌入到可执行文件的方法是,需要在生成exe之后在执行下面的命令:

mt.exe –manifest $(APP).exe.manifest -outputresource:$(APP).exe;1

编译DLL的话,有一点点小区别的。

mt.exe –manifest $(LIB).dll.manifest -outputresource:$(LIB).dll;2

后话
VC2005搞出个这玩意有什么好处?

About 王永杰

路漫漫其修远兮,吾将上下而求索
This entry was posted in C&C++. Bookmark the permalink.

One Response to VS2005 编译环境,解决 Runtime Error(运行时错误): R6034。

  1. Lucien says:

    It would be interesting to know details

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>