???DLL的一个难题

byxdaz
博客专家认证
2005-05-18 12:04:58
有一个.OBJ文件里面有一个变量int ImageWidth,这个.OBJ文件没有源代码的,是别人做的。现在要做一个DLL,这个DLL程序中要用到这个变量(ImageWidth),而且要把ImageWidth这个变量以C的形式输出。请问有什么办法可以实现。
另外的OBJ中的int ImageWidth是公用变量。(.OBJ文件是ThresholdReprocess.obj和PreThreshold.obj,这两个OBJ文件没有源代码的,是别人做的)
如果在DLL中加入 extern _declspec(dllexport) int ImageWidth;没有问题,就会以C++的形式导出ImageWidth变量。如果在DLL中加入 extern “C”extern _declspec(dllexport) int ImageWidth;
出现下面的错误:(程序是用VC编译的,目的是把变量ImageWidth按C的形式导出)
ThresholdReprocess.obj : error LNK2001: unresolved external symbol "int ImageWidth" (?ImageWidth@@3HA)
PreThreshold.obj : error LNK2001: unresolved external symbol "int ImageWidth" (?ImageWidth@@3HA)
Debug/SealCreatLib.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Creating browse info file...

SealCreatLib.dll - 3 error(s)
...全文
165 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
idAnts 2005-05-19
  • 打赏
  • 举报
回复
有obj也可以,不用lib,你把obj加到你的工程里了么?
younggle 2005-05-19
  • 打赏
  • 举报
回复
要有.lib才行啊,有.obj有什么用呢?
byxdaz 2005-05-19
  • 打赏
  • 举报
回复
不行啊
ThresholdReprocess.obj : error LNK2001: unresolved external symbol "int ImageWidth" (?ImageWidth@@3HA)
byxdaz 2005-05-18
  • 打赏
  • 举报
回复
在DLL中我加了extern int ImageWidth;
还是不行?
extern _declspec(dllexport) int ImageWidth;跟extern int ImageWidth;是等价了,只是前者导出变量而已。
dongfa 2005-05-18
  • 打赏
  • 举报
回复
加入
extern int ImageWidth;
试试.
idAnts 2005-05-18
  • 打赏
  • 举报
回复
extern "C" {
extern int ImageWidth;
}
int ImageWidth;
再用。

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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