序:项目中遇到的一个问题,工程从VS2003平台升级到VS2005平台。以前一切正常的工程在VS2005下面出现了大量的error LNK2005,下面讲述解决办法。
LIBCMT.lib(calloc.obj) : error LNK2005: _calloc already defined in winalloc.obj
LIBCMT.lib(realloc.obj) : error LNK2005: _realloc already defined in winalloc.obj
第一感觉是库出现了冲突,在把编译选项的MFC项由static改成shared后error全部消失,但是由于工程原因,这种改法存在隐患,在linker的commond line里面加入 /FORCE:MULTIPLE,问题解决了,但是留下一大堆的link warning,对于我这种严谨的人来说,warning也是要解决的,继续研究。
于是寻找新的解决方法,Google,呵呵,在MSDN的论坛上发现有人有和我一样的问题。
发个链接给大家。http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=133141&SiteID=1
把最重要的官方发言发贴一下。
OK,确定是微软的问题。我走上了一条正确的道路。warning没有问题。只有等微软发补丁了。
Hi Bill:
Well, this one sure turned into a lot of fun, and you get the bug finder's award for today...
The multiply defined symbols problem is caused by a bug in our implementation of calloc and realloc. This bug has been brought to the attention of our devs and hopefully can be addressed in an upcoming service pack.
Since we get lucky using the /FORCE:MULTIPLE linker switch (that is - it picks up the winalloc.obj versions first and ignores the libcmt.lib versions), that is probably your best workaround for now. I want to stress that this is a workaround and using the /FORCE linker switch should never be necessary or a common practice. If this unblocks you, that is your workaround for the time being. If the exe you generate with this switch has other problems, please post that fact up here - there may be another workaround, but it is complicated and risky.
Best Regards,