error LNK2019: unresolved external symbol

这篇文章解决了我的燃眉之急。

转载自:http://blog.csdn.net/jtop0/article/details/5779782

error LNK2019: unresolved external symbol

(2007-05-28 10:23:43)

错误是解决了一个又一个,记下来权当是经验了。
共有11个类似的错误,我列出1个来。
模板:
template<class T>
void Blur(T* SourceImage, const int Width, const int Height);
 
template void
Blur<unsigned char>
(unsigned char*, const int, const int);
 
但链接时出错
Linking...
Image_demoDoc.obj : error LNK2019: unresolved external symbol "void __cdecl Blur<unsigned char>(unsigned char *,int,int)" (??$Blur@E@@YAXPAEHH@Z) referenced in function "void __cdecl OnBlur(struct HWND__ *)" (?OnBlur@@YAXPAUHWND__@@@Z)
Release/Image_demo.exe : fatal error LNK1120 : 11 unresolved externals
 
折腾了4个小时,终于搞出来了。当然类似的错误百度搜索一大堆。我也查出原因了: 模板声明和实现要放在同一文件夹中 ,我原先把声明放在了.h文件中,把实现放在了.cpp文件中。改了后运行还是出错。真是奇怪!我还以为是什么大的错误。后来重新启动了下VS2005就好了。原来我修改后,编译环境还以以前就的中间文件来编译,怪不得改了后还是没用。现在发现,有时候这VC环境还是有点“反应慢”。

其实,LNK2019错误一般都是 compile是能找到相应的header (.h)文件,但链接时找不到相应的 lib 库文件(也含dll文件)。如 昨天调试时再linux下 pointcloudviewerJ 项目能compile 和link 正确,但在 windows下设置了项目 属性 后 能compile 但link 时 报错如下:
1>Linking...
1>LINK : D:/Experiment_Data/Microsoft VC9/PointCloudViewerJ/Debug/PointCloudViewerJ.exe not found or not built by the last incremental link; performing full link
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall osgGA::StateSetManipulator::StateSetManipulator(class osg::StateSet *)" (__imp_??0StateSetManipulator@osgGA@@QAE@PAVStateSet@osg@@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall osgGA::TrackballManipulator::TrackballManipulator(void)" (__imp_??0TrackballManipulator@osgGA@@QAE@XZ) referenced in function _main
。。。。。。。。
D:/Experiment_Data/Microsoft VC9/PointCloudViewerJ/Debug/PointCloudViewerJ.exe : fatal error LNK1120: 11 unresolved externals
这就是说一个link失败,使由于osgGA::StateSetManipulator::............的unresolved external symbol, 也就是说 一定是osgGA库出了问题 。check 项目属性,发现 Additional Dependencies 中没有osgGA.lib  ,  所以 加上 osgGAd.lib(因为用的是Debug版)。rebuild 项目。compile 和link 通过。
另:有时候前面函数的声明 与 后面的  函数的定义 时的参数类型不同时,compile能通过,但link会出现LNK2019错误!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值