问题: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描述的:
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。
解决办法
解决方法有两个:
- 将编译得到的 $(APP).exe.manifest 一并打包,即和应用程序放在同一个文件夹下;
- 将manifest文件直接嵌入到可执行文件。
嵌入到可执行文件的方法是,需要在生成exe之后在执行下面的命令:
mt.exe –manifest $(APP).exe.manifest -outputresource:$(APP).exe;1
编译DLL的话,有一点点小区别的。
mt.exe –manifest $(LIB).dll.manifest -outputresource:$(LIB).dll;2
后话
VC2005搞出个这玩意有什么好处?