EVC工程属性use mfc in a static library 转化为 use mfc in a shared dll的问题

datoucaicai 2009-09-01 02:52:36
EVC平台下
将工程属性由use mfc in a static library 转化为 use mfc in a shared dll以后,出现100多个连接错误,错误提示大概如下:
Linking...
uafxwce.lib(thrdcore.obj) : error LNK2005: "class CWinThread * __cdecl AfxBeginThread(unsigned int (__cdecl*)(void *),void *,int,unsigned int,unsigned long,struct _SECURITY_ATTRIBUTES *)" (?AfxBeginThread@@YAPAVCWinThread@@P6AIPAX@Z0HIKPAU_SECURITY_ATTRIBUTES@@@Z) already defined in MFCCE400.lib(mfcce400.dll)
uafxwce.lib(thrdcore.obj) : error LNK2005: "public: virtual void __cdecl CWinThread::Delete(void)" (?Delete@CWinThread@@UAAXXZ) already defined in MFCCE400.lib(mfcce400.dll)
都提示一些MFC函数在MFCCE400.lib中重复定义

但新建一个工程,将工程属性由use mfc in a static library 转化为 use mfc in a shared dll重新编译就不会有问题

大侠们来救命哈,焦头烂额中啊

原帖地址为:
http://topic.csdn.net/u/20090805/16/371de98d-b117-4c28-b8cf-2f4550187412.html
...全文
200 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
tiny_god 2011-05-08
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 datoucaicai 的回复:]
感谢13楼的conry,经过测试确实有一个第三方的库静态编译了,去掉这个库就编译通过啦

非常感谢!
[/Quote]
我现在也遇到这个问题,想问下怎么测试引用了哪些库
echo41 2010-01-12
  • 打赏
  • 举报
回复
upup
qdhzq 2009-09-12
  • 打赏
  • 举报
回复
dgfdhgfghfghgfh
datoucaicai 2009-09-02
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 socoola 的回复:]
引用 7 楼 datoucaicai 的回复:
引用 4 楼 socoola 的回复:
所以去掉_AFXDLL的预编译宏


在我的原帖里说明了,需要添加支持Active X控件,需要包含头文件#include  <afxdisp.h>
而afxdisp.h是需要定义_AFXDLL的

没仔细看,一定要加上_AFXDLL宏才行。
你的问题是由于引入了静态链接MFC库uafxwce.lib,我查看了引入uafxwce.lib的代码,在afx.h中:
C/C++ code#ifndef _AFXDLL
#ifdef _DEBUG#pragma comment(lib, "uafxwced.lib")#else#pragma comment(lib, "uafxwce.lib")#endif#else
#ifdef _DEBUG#pragma comment(lib, "mfcs42d.lib")#pragma comment(lib, WCE_MFC_FILENAME(d.lib))#else#pragma comment(lib, "mfcs42.lib")#pragma comment(lib, WCE_MFC_FILENAME(.lib))#endif#endif
很明显,是否链接uafxwce.lib是由_AFXDLL控制,而你定义了宏,所以不可能会被链接到工程。

我猜测有一个可能,问题由于你的工程没有重新rebuild all导致,删掉你工程下的pch,pdb文件再rebuild all一次试试。

[/Quote]

首先感谢这位大侠的热心,这个工程rebuild all了无数次了,错误还是一样
如果这些错误是由“静态链接MFC库uafxwce.lib”引起,那根据你给的这段代码,定义了_AFXDLL的话,这个库uafxwce.lib是不会被链接到工程啊
huangege123 2009-09-02
  • 打赏
  • 举报
回复
UP
UP

rebuild一下
datoucaicai 2009-09-02
  • 打赏
  • 举报
回复
感谢13楼的conry,经过测试确实有一个第三方的库静态编译了,去掉这个库就编译通过啦

非常感谢!
datoucaicai 2009-09-02
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 conry 的回复:]
你的工程是不是引用其他的静态编译的库了,如果是的话改成动态试试
[/Quote]

这个倒有可能,我测试看看
你妹的特盗不 2009-09-02
  • 打赏
  • 举报
回复
这个原因是,因为你的一些定义引起的,因为你创建的时候,选的什么,对应的定义已经产生了,你改后,那些定义不会去掉,所以会有问题,还有function使用方面也有一些注意的~~

这问题有点复杂
Conry 2009-09-02
  • 打赏
  • 举报
回复
你的工程是不是引用其他的静态编译的库了,如果是的话改成动态试试
晒月光的青蛙 2009-09-01
  • 打赏
  • 举报
回复
没试过呢,帮顶吧
  • 打赏
  • 举报
回复
UP
socoola 2009-09-01
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 datoucaicai 的回复:]
引用 4 楼 socoola 的回复:
所以去掉_AFXDLL的预编译宏


在我的原帖里说明了,需要添加支持Active X控件,需要包含头文件#include <afxdisp.h>
而afxdisp.h是需要定义_AFXDLL的
[/Quote]
没仔细看,一定要加上_AFXDLL宏才行。
你的问题是由于引入了静态链接MFC库uafxwce.lib,我查看了引入uafxwce.lib的代码,在afx.h中:
#ifndef _AFXDLL
#ifdef _DEBUG
#pragma comment(lib, "uafxwced.lib")
#else
#pragma comment(lib, "uafxwce.lib")
#endif
#else
#ifdef _DEBUG
#pragma comment(lib, "mfcs42d.lib")
#pragma comment(lib, WCE_MFC_FILENAME(d.lib))
#else
#pragma comment(lib, "mfcs42.lib")
#pragma comment(lib, WCE_MFC_FILENAME(.lib))
#endif
#endif

很明显,是否链接uafxwce.lib是由_AFXDLL控制,而你定义了宏,所以不可能会被链接到工程。

我猜测有一个可能,问题由于你的工程没有重新rebuild all导致,删掉你工程下的pch,pdb文件再rebuild all一次试试。
datoucaicai 2009-09-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 socoola 的回复:]
所以去掉_AFXDLL的预编译宏
[/Quote]

在我的原帖里说明了,需要添加支持Active X控件,需要包含头文件#include <afxdisp.h>
而afxdisp.h是需要定义_AFXDLL的
jyh_baoding 2009-09-01
  • 打赏
  • 举报
回复
看看你的宏定义和预编译的部分是不是有控制程序的设置
hhwei1985 2009-09-01
  • 打赏
  • 举报
回复
up
socoola 2009-09-01
  • 打赏
  • 举报
回复
所以去掉_AFXDLL的预编译宏
socoola 2009-09-01
  • 打赏
  • 举报
回复
When you use the Windows CE MFC library as a shared DLL, define _AFXDLL in your preprocessor definitions. This will cause your project to be linked with the Mfcce20.lib export library and the Mfcs42.lib static helper library. If your project supports ActiveX, it will also be linked with the Olece20.lib export library.

When you use the Windows CE MFC library as a statically linked library,do not define _AFXDLL. If _AFXDLL is not defined, your project will be linked with the static MFC library, uafxwce.lib.
datoucaicai 2009-09-01
  • 打赏
  • 举报
回复
好像只有这样啦,不过这是最后的办法
oyljerry 2009-09-01
  • 打赏
  • 举报
回复
既然新建可以,那么新建以后,再添加代码...

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧