error LNK2019: unresolved external symbol

error LNK2019: unresolved external symbol

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

转载
  分类: Programe(C/C++/VC/.NET)
错误是解决了一个又一个,记下来权当是经验了。
共有11个类似的错误,我列出1个来。
模板:
template
void Blur(T* SourceImage, const int Width, const int Height);
 
template void
Blur
(unsigned char*, const int, const int);
 
但链接时出错
Linking...
Image_demoDoc.obj : error LNK2019: unresolved external symbol "void __cdecl Blur(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错误!

你可能感兴趣的:(error LNK2019: unresolved external symbol)