OpenCV linker problem (Bug #2372)
Description
Hello,
Since this is my first post, I will try to make it as clear as possible so that people could try to find the reason of this error together with me.
Brief: I am running openCV 2.4.2 on Windows 7 x64 and with Visual Studio 2010 C++ compiler
As followed by multiple guides online I made sure the following configurations were made
1) Be sure that Visual Studio knows that the win32 console application is for x64 bit system
2) At the C/C++ general settings of the project I got the following additional include directories
D:\OpenCV2.4\build\include
D:\OpenCV2.4\build\include\opencv
D:\OpenCV2.4\build\include\opencv2
3) At the linker settings I added at general settings the following additional library directory
D:\OpenCV2.4\build\x64\vc10\lib\
4) At the linker settings I added at the input settings the following additional dependencies
opencv_core240d.lib
opencv_imgproc240d.lib
opencv_highgui240d.lib
opencv_objdetect240d.lib
opencv_calib3d240d.lib
opencv_video240d.lib
opencv_features2d240d.lib
opencv_flann240d.lib
opencv_legacy240d.lib
Included inside the project is all the files that can be found for the traincascade application under the folder: D:\OpenCV2.4\apps\traincascade\.
This all should be enough to compile the traincascade.cpp file, in order to be able to train a classifier myself.
But I keep getting the following linking errors:
1>------ Build started: Project: traincascade, Configuration: Debug x64 ------
1>Build started 19/09/2012 16:02:53.
1>InitializeBuildStatus:
1> Touching "x64\Debug\traincascade.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>traincascade.obj : error LNK2019: unresolved external symbol "public: bool __cdecl CvCascadeClassifier::train(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,int,int,int,int,classCvCascadeParams const &,class CvFeatureParams const &,struct CvCascadeBoostParams const &,bool)" (?train@CvCascadeClassifier@QEAA_NV?$basic_string@DU?$char_traits@D@std
@V?$allocator@D@2@std
@00HHHHHAEBVCvCascadeParams@AEBVCvFeatureParams
@AEBUCvCascadeBoostParams@_N@Z) referenced in function main
@UEAA_NV?$basic_string@DU?$char_traits@D@std@
1>traincascade.obj : error LNK2019: unresolved external symbol "public: virtual bool __cdecl CvCascadeBoostParams::scanAttr(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?scanAttr@CvCascadeBoostParamsV?$allocator@D@2
@std@0@Z) referenced in function main
@UEAA_NV?$basic_string@DU?$char_traits@D@std@
1>traincascade.obj : error LNK2019: unresolved external symbol "public: virtual bool __cdecl CvCascadeParams::scanAttr(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?scanAttr@CvCascadeParamsV?$allocator@D@2
@std@0@Z) referenced in function main
@UEBAXXZ) referenced in function main
1>traincascade.obj : error LNK2019: unresolved external symbol "public: virtual void __cdecl CvCascadeBoostParams::printDefaults(void)const " (?printDefaults@CvCascadeBoostParams
1>traincascade.obj : error LNK2019: unresolved external symbol "public: virtual void __cdecl CvCascadeParams::printDefaults(void)const " (?printDefaults@CvCascadeParams@UEBAXXZ) referenced in function main
@QEAA@XZ) referenced in function main
1>traincascade.obj : error LNK2019: unresolved external symbol "public: __cdecl CvHOGFeatureParams::CvHOGFeatureParams(void)" (??0CvHOGFeatureParams
1>traincascade.obj : error LNK2019: unresolved external symbol "public: __cdecl CvLBPFeatureParams::CvLBPFeatureParams(void)" (0CvLBPFeatureParams@QEAA@XZ) referenced in function main
@QEAA@XZ) referenced in function main
1>traincascade.obj : error LNK2019: unresolved external symbol "public: __cdecl CvHaarFeatureParams::CvHaarFeatureParams(void)" (??0CvHaarFeatureParams
1>traincascade.obj : error LNK2019: unresolved external symbol "public: __cdecl CvCascadeBoostParams::CvCascadeBoostParams(void)" (??0CvCascadeBoostParams@QEAA@XZ) referenced in function main
@QEAA@XZ) referenced in function main
1>traincascade.obj : error LNK2019: unresolved external symbol "public: __cdecl CvCascadeParams::CvCascadeParams(void)" (??0CvCascadeParams
1>traincascade.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl CvCascadeBoostParams::printAttrs(void)const " (?printAttrs@CvCascadeBoostParams@UEBAXXZ)
@UEBAXXZ)
1>traincascade.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl CvParams::printDefaults(void)const " (?printDefaults@CvParams
1>traincascade.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl CvParams::printAttrs(void)const " (?printAttrs@CvParams@UEBAXXZ)
@UEAA_NV?$basic_string@DU?$char_traits@D@std@
1>traincascade.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl CvParams::scanAttr(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?scanAttr@CvParamsV?$allocator@D@2
@std@0@Z)
@UEAA@XZ) referenced in function "int `public: __cdecl CvCascadeImageReader::CvCascadeImageReader(void)'::`1'::dtor$0" (?dtor$0@?0?0CvCascadeImageReader@
1>traincascade.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl CvCascadeImageReader::PosReader::~PosReader(void)" (??1PosReader@CvCascadeImageReaderQEAA@XZ@4HA)
@QEAA@XZ) referenced in function "public: __cdecl CvCascadeImageReader::CvCascadeImageReader(void)" (??0CvCascadeImageReader@
1>traincascade.obj : error LNK2019: unresolved external symbol "public: __cdecl CvCascadeImageReader::NegReader::NegReader(void)" (??0NegReader@CvCascadeImageReaderQEAA@XZ)
@QEAA@XZ) referenced in function "public: __cdecl CvCascadeImageReader::CvCascadeImageReader(void)" (??0CvCascadeImageReader@@QEAA@XZ)
1>traincascade.obj : error LNK2019: unresolved external symbol "public: __cdecl CvCascadeImageReader::PosReader::PosReader(void)" (??0PosReader@CvCascadeImageReader
1>D:\ProjectTest\ClassifierTraining\x64\Debug\traincascade.exe : fatal error LNK1120: 17 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.51
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I discussed this issue with my current research group and none seems to find the answer to the problem, since we are all agreed that the correct libraries are added to the project, containing the functions the linker has problems with.
Anyone has any clue on how this could be solved?
Or is this a bug for this specific configuration of windows/openCV/visual studio?
Kind regards,
Steven
ps. I have added the complete source code to this bug report
History
Updated by Steven Puttemans over 12 years ago
Since the adding of a *.rar file did not work, here is my code:
--------------------------------
#include "cv.h"
#include "cascadeclassifier.h"
using namespace std;
int main( int argc, char* argv[] )
{
CvCascadeClassifier classifier;
String cascadeDirName, vecName, bgName;
int numPos = 2000;
int numNeg = 1000;
int numStages = 20;
int precalcValBufSize = 256,
precalcIdxBufSize = 256;
bool baseFormatSave = false;
CvCascadeParams cascadeParams;
CvCascadeBoostParams stageParams;
Ptr<CvFeatureParams> featureParams[] = { Ptr<CvFeatureParams>(new CvHaarFeatureParams),
Ptr<CvFeatureParams>(new CvLBPFeatureParams),
Ptr<CvFeatureParams>(new CvHOGFeatureParams)
};
int fc = sizeof(featureParams)/sizeof(featureParams[0]);
if( argc == 1 )
{
cout << "Usage: " << argv[0] << endl;
cout << " -data <cascade_dir_name>" << endl;
cout << " -vec <vec_file_name>" << endl;
cout << " -bg <background_file_name>" << endl;
cout << " [-numPos <number_of_positive_samples = " << numPos << ">]" << endl;
cout << " [-numNeg <number_of_negative_samples = " << numNeg << ">]" << endl;
cout << " [-numStages <number_of_stages = " << numStages << ">]" << endl;
cout << " [-precalcValBufSize ]" << endl;
cout << " [-precalcIdxBufSize <precalculated_idxs_buffer_size_in_Mb = " << precalcIdxBufSize << ">]" << endl;
cout << " [-baseFormatSave]" << endl;
cascadeParams.printDefaults();
stageParams.printDefaults();
for( int fi = 0; fi < fc; fi++ )
featureParams[fi]->printDefaults();
return 0;
}
for( int i = 1; i < argc; i++ )
{
bool set = false;
if( !strcmp( argv[i], "-data" ) )
{
cascadeDirName = argv[++i];
}
else if( !strcmp( argv[i], "-vec" ) )
{
vecName = argv[++i];
}
else if( !strcmp( argv[i], "-bg" ) )
{
bgName = argv[++i];
}
else if( !strcmp( argv[i], "-numPos" ) )
{
numPos = atoi( argv[++i] );
}
else if( !strcmp( argv[i], "-numNeg" ) )
{
numNeg = atoi( argv[++i] );
}
else if( !strcmp( argv[i], "-numStages" ) )
{
numStages = atoi( argv[++i] );
}
else if( !strcmp( argv[i], "-precalcValBufSize" ) )
{
precalcValBufSize = atoi( argv[++i] );
}
else if( !strcmp( argv[i], "-precalcIdxBufSize" ) )
{
precalcIdxBufSize = atoi( argv[++i] );
}
else if( !strcmp( argv[i], "-baseFormatSave" ) )
{
baseFormatSave = true;
}
else if ( cascadeParams.scanAttr( argv[i], argv[i+1] ) ) { i++; }
else if ( stageParams.scanAttr( argv[i], argv[i+1] ) ) { i++; }
else if ( !set )
{
for( int fi = 0; fi < fc; fi++ )
{
set = featureParams[fi]->scanAttr(argv[i], argv[i+1]);
if ( !set )
{
i++;
break;
}
}
}
}
classifier.train( cascadeDirName,
vecName,
bgName,
numPos, numNeg,
precalcValBufSize, precalcIdxBufSize,
numStages,
cascadeParams,
*featureParams[cascadeParams.featureType],
stageParams,
baseFormatSave );
return 0;
}
Updated by Kazuki Matsuda over 12 years ago
Hi.
Brief: I am running openCV 2.4.2 on Windows 7 x64 and with Visual Studio 2010 C++ compiler
Are you using 2.4.2, right? In next paragraph, It can be read as you are going to link 2.4.0 libraries.
(But I think it is simple typo because "library not found error" is not reported)
I found Machine Learning Library opencv_ml242d.lib is missing.4) At the linker settings I added at the input settings the following additional dependencies
opencv_core240d.lib
opencv_imgproc240d.lib
opencv_highgui240d.lib
opencv_objdetect240d.lib
opencv_calib3d240d.lib
opencv_video240d.lib
opencv_features2d240d.lib
opencv_flann240d.lib
opencv_legacy240d.lib
In my revision (4662), app/traincascade needs next 4 libraries actuary
- opencv_ml242d.lib
- opencv_highgui242d.lib
- opencv_core242d.lib
- opencv_imgproc242d.lib
and you can see all specified dependencies at apps/traincascade/CMakeLists.txt (http://code.opencv.org/projects/opencv/repository/revisions/master/entry/apps/traincascade/CMakeLists.txt
)
5 : SET(OPENCV_TRAINCASCADE_DEPS opencv_core opencv_ml opencv_imgproc opencv_objdetect opencv_highgui opencv_calib3d opencv_video opencv_features2d opencv_flann opencv_legacy)
are your problems resolved?
Updated by Andrey Kamaev over 12 years ago
- Target version changed from 2.4.3 to 2.4.3-rc
Updated by Evgeny Talanin over 12 years ago
Steven, did you try Kazuki's solution?
You can also try OpenCV version 2.4.3 or code from master branch.
If it doesn't help, please reopen the ticket.
- Assignee changed from Alexander Shishkov to Steven Puttemans
- Status changed from Open to Cancelled
Updated by Steven Puttemans almost 12 years ago
I am sorry for not following on my own tickets. Opened this when I was just a member of the OpenCV community. Function does exactly what it should do now, probably was lack of experience and forgetting to include all depending libraries.
Thanks anyway!