VS2008,2005,2003应用程序配置不正确(整合)

VC++ 2005编译出程序在XP下执行出错的解决方法

这个问题主要出现在XP环境下运行由Visual C++2003/2005编译的MFC程序时  
问题现象是XP运行此类程序时,报错"由于应用程序配置不正确,应用程序未能启动.重新安装应用程序可能会纠正这个问题"  
这个问题似乎许多人遇见过.在CSDN和微软社区里面都有人提到.但是没有完整的解决方案  
这个问题的解决一共会遇见2个子问题  

最早出现这个错误我和许多人认为的一样  
认为是缺乏DLL库文件导致.但是在测试机复制了DLL甚至安装了.net framework 2.0以后  
都无法解决问题,最后确认不是由缺乏DLL所致  
因为程序是纯win32的应用程,非托管代码,所以也无需.net framework  

Visual C++2003/2005默认的MFC程序是使用动态MFC库(Use MFC in a Shared DLL)来链接的  
而动态MFC库使用的是Multi-threaded DLL (/MD)  
由于XP对于PE文件格式监测更加严格.  
就会导致部分使用多线程DLL的可执行文件在调用的时候出错  
修改项目属性的编译开关  
Project->Property->configuration Properties->C/C++->Code Generation->Runtime Library  
修改成Multi-threaded (/MT)  
修改了Runtime类型以后  
需要将MFC的编译类型也改成静态库  
Project->Property->configuration Properties->General->Use of MFC  
修改成Use MFC in a Static Library  
一部分情况下在这步就能解决问题  
另外一部分情况会遇见如下情况  
编译器报错  

CODE:  
nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmt.lib(newaop.obj)  
[Copy to clipboard]  


产生这个问题的原因是库依赖关系  
在Project->Property->configuration Properties->Linker->Command Line  
加入编译开关/verbose:lib可以显示详细的库链接顺序  

CODE:  

------ Build started: Project: PerfMonDemo, Configuration: Release Win32 ------  
Linking...  
Searching libraries  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/pdh.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/DelayImp.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/libcpmt.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/atlmfc/lib/nafxcw.lib:  
nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmt.lib(newaop.obj)  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/libcmt.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/kernel32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/user32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/gdi32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/msimg32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/comdlg32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/winspool.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/advapi32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/shell32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/comctl32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/shlwapi.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/uuid.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/oledlg.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/ole32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/oleaut32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/urlmon.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/OLDNAMES.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/atlmfc/lib/atls.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/ws2_32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/mswsock.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/oleacc.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/pdh.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/DelayImp.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/libcpmt.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/atlmfc/lib/nafxcw.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/libcmt.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/kernel32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/user32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/gdi32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/msimg32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/comdlg32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/winspool.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/advapi32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/shell32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/comctl32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/shlwapi.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/uuid.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/oledlg.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/ole32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/oleaut32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/urlmon.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/OLDNAMES.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/atlmfc/lib/atls.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/ws2_32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/mswsock.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/oleacc.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/pdh.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/DelayImp.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/libcpmt.lib:  
Finished searching libraries  
Searching libraries  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/pdh.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/DelayImp.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/libcpmt.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/atlmfc/lib/nafxcw.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/libcmt.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/kernel32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/user32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/gdi32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/msimg32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/comdlg32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/winspool.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/advapi32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/shell32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/comctl32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/shlwapi.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/uuid.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/oledlg.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/ole32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/oleaut32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/urlmon.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/OLDNAMES.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/atlmfc/lib/atls.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/ws2_32.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/mswsock.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/oleacc.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/lib/pdh.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/DelayImp.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/lib/libcpmt.lib:  
   Searching d:/Program Files/Microsoft Visual Studio 8/VC/atlmfc/lib/nafxcw.lib:  
Finished searching libraries  
./Release/PerfMonDemo.exe : fatal error LNK1169: one or more multiply defined symbols found  
Build log was saved at "file://d:/Dev/Performance Monitor/Release/BuildLog.htm"  
PerfMonDemo - 2 error(s), 0 warning(s)  
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========  

[Copy to clipboard]  

我们发现在libcpmt.lib声明过的operator new在nafxcw.lib中再次定义  
解决方法如下  
Project->Property->configuration Properties->Linker->Input->Additional Dependencies  
加入  
nafxcw.lib  
libcpmt.lib  
Project->Property->configuration Properties->Linker->Input->Ignore Specific Library  
加入  
nafxcw.lib  
libcpmt.lib  
这样链接程序就不会先按照默认顺序来连接这两个库文件  
而是在最后在加入对他们的引用.这样就避免了这个问题   
下面是一张可能发生冲突的列表  
若要使用此运行时库 请忽略这些库   
单线程 (libc.lib) libcmt.lib、msvcrt.lib、libcd.lib、libcmtd.lib、msvcrtd.lib   
多线程 (libcmt.lib) libc.lib、msvcrt.lib、libcd.lib、libcmtd.lib、msvcrtd.lib   
使用 DLL 的多线程 (msvcrt.lib) libc.lib、libcmt.lib、libcd.lib、libcmtd.lib、msvcrtd.lib   
调试单线程 (libcd.lib) libc.lib、libcmt.lib、msvcrt.lib、libcmtd.lib、msvcrtd.lib   
调试多线程 (libcmtd.lib) libc.lib、libcmt.lib、msvcrt.lib、libcd.lib、msvcrtd.lib   
使用 DLL 的调试多线程 (msvcrtd.lib) libc.lib、libcmt.lib、msvcrt.lib、libcd.lib、libcmtd.lib

----再转一个方法(3)

   在使用 VC++2005环境下生成的程序,放置到未安装VC环境的机器下后,有时候会出现程序无法执行的错误,其提示是:应用程序配置不正确,程序无法启动,重新安装应用程序可能解决问题。

      实际上,重装是解决不了问题的,解决的一种方法是查看*exe.intermediate.manifest文件,比如文件的内容是:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>

<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>

 <dependency>

    <dependentAssembly>

      <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />

    </dependentAssembly>

 </dependency>

 <dependency>

    <dependentAssembly>

      <assemblyIdentity type='win32' name='Microsoft.VC80.MFC' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />

    </dependentAssembly>

 </dependency>

 <dependency>

    <dependentAssembly>

      <assemblyIdentity type='win32' name='Microsoft.VC80.DebugCRT' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />

    </dependentAssembly>

 </dependency>

</assembly>

       需要注意这个文件中的3个关键词:Microsoft.VC80.CRTMicrosoft.VC80.MFCMicrosoft.VC80.DebugCRT寻找到...."Program Files"Microsoft Visual Studio 8"VC"redist文件夹下面,找到这些名称的子文件夹,拷贝它们下面所有的文件到希望发布的EXE文件下面,一起打包。这些文件也就是mfc80.dllmsvcr80.dllmsvcp80.dllMicrosoft.VC80.CRT.manifest等。此错误发生的原因是在目标机器上需要这些文件的支持。

---要是还是整不好,你就看看下面的链接吧

http://hi.baidu.com/fairysky/blog/item/e7a8366dbaa735f3431694c8.html

阅读更多
个人分类: MFC
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

VS2008,2005,2003应用程序配置不正确(整合)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭