CUDA在Debug下编译有错而Release下无错

本文解决了一个常见的编程问题,在使用MSVCRT和LIBCMT库时遇到的链接错误。通过调整编译选项和库设置,最终解决了运行时出现的错误提示。

错误提示:

1>LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __decode_pointer already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(setlocal.obj) : error LNK2005: __configthreadlocale already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __cexit already defined in msvcrtd.lib(MSVCR90D.dll)

在经过搜索后采用了忽略 msvcrtd.lib,额外的库添加:LIBCMT.lib

这样可以编译通过,但是Debug版本运行后很多错误提示。

后加入群,两个人的意见有建设性!

1. 改成MTD,但现在编译会提示

1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxver_.h(81) : fatal error C1189: #error :  Please use the /MD switch for _AFXDLL builds
然后他说: 也就是改用静态库,同时MTD。编译运行通过

_AFXDLL tells the compiler to use the DLL version of the MFC libraries. But when you do this you must also use the DLL version of the CRT libraries (/MD compiler option).
 
When you switched to static linking, you should have changed to "Use MFC in a static library" (as Hans told you). This would have automatically changed your CRT setting to /MT. But it seems that you just changed to /MT without changing the MFC setting, so your project was inconsistent. When you got rid of _AFXDLL, the compiler thought you did not want MFC at all, so it did not recognize the MFC calls.
2.

把这两个目录:

SPH-CUDA(736183739) 17:40:36
C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\common
SPH-CUDA(736183739) 17:40:50
C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\shared
下的重新用MDd编译。默认的是用MT编译的,而我们自己自动生成的MFC里默认是MD编译的,也就是不一致!

但这个我后来再改第一个方法成功后没有尝试这个。

转载于:https://www.cnblogs.com/kyleada/archive/2011/08/11/2135352.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值