问题
我正在尝试启动并运行OpenCV,但我遇到了与this guy和this guy相同的问题 - 在尝试使用C ++接口构建项目时出现链接器错误,但是项目构建的C接口。
在第二个链接中,答案是“你正在混合不同的STL实现.VC10(用于OpenCV)和STLPort(用于你的代码)。”
如何确保我只使用VC10? (或更高版本)
C样式(项目构建成功)
我正在使用Visual Studio 2012和OpenCV 3.0
int main( int argc, char** argv )
{
char* filename = "input.tif";
IplImage *img0;
if( (img0 = cvLoadImage(filename,-1)) == 0 )
return 0;
cvNamedWindow( "image", 0 );
cvShowImage( "image", img0 );
cvWaitKey(0);
cvDestroyWindow("image");
cvReleaseImage(&img0);
}
C ++样式(Project不构建)
int main( int argc, char** argv ) {
Mat image;
const string &filename = "input.tif";
image = imread(filename, IMREAD_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
std::cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
}
错误:
1>Source.obj : error LNK2019: unresolved external symbol "private: char * __thiscall cv::String::allocate(unsigned int)" (?allocate@String@cv@@AAEPADI@Z) referenced in function "public: __thiscall cv::String::String(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0String@cv@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>Source.obj : error LNK2019: unresolved external symbol "private: void __thiscall cv::String::deallocate(void)" (?deallocate@String@cv@@AAEXXZ) referenced in function "public: __thiscall cv::String::~String(void)" (??1String@cv@@QAE@XZ)
1>Source.obj : error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class cv::String const &,int)" (?imread@cv@@YA?AVMat@1@ABVString@1@H@Z) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class cv::String const &,int)" (?namedWindow@cv@@YAXABVString@1@H@Z) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class cv::String const &,class cv::_InputArray const &)" (?imshow@cv@@YAXABVString@1@ABV_InputArray@1@@Z) referenced in function _main
VS中的包含和lib路径设置
答案 0 :(得分:1)
从聊天讨论中可以看出,OP与OpenCV 2.4.10而不是OpenCV 3.0相关联。
通过更正链接库,问题得以解决。