【问题标题】:Fixing mixed STL implementation with OpenCV使用 OpenCV 修复混合 STL 实现
【发布时间】:2015-10-13 12:18:42
【问题描述】:

问题

我正在尝试启动并运行 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++ 风格(项目不构建)

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中的include和lib路径设置

  • C/C++/General/Additional 包含目录: C:\opencv\build\include
  • 链接器/常规/附加库目录: \n C:\opencv\build\x86\vc11\lib
  • 链接器/输入/附加依赖: opencv_calib3d2410d.lib opencv_contrib2410d.lib opencv_core2410d.lib opencv_features2d2410d.lib opencv_flann2410d.lib opencv_gpu2410d.lib opencv_highgui2410d.lib opencv_imgproc2410d.lib opencv_legacy2410d.lib opencv_ml2410d.lib opencv_nonfree2410d.lib opencv_objdetect2410d.lib opencv_ocl2410d.lib opencv_photo2410d.lib opencv_stitching2410d.lib opencv_superres2410d.lib opencv_ts2410d.lib opencv_video2410d.lib opencv_videostab2410d.lib

【问题讨论】:

  • 你能显示你的#include吗?你的库路径呢?
  • 我添加了对解决方案属性所做的更改
  • @Attaque 我很确定你不是指stl,删除了标签。请在下次添加之前阅读标签wiki。此外,您应该更改问题中的文本并改为参考 c++ 标准库。
  • 我很抱歉。由于它是基于我链接的其他问题,我没有考虑太多。这可能是问题的一部分,我不需要使用与 VS 提供的库不同的库。你能不能改变一下?
  • 只要你的 VS 项目是 32 位的,这应该可以工作

标签: c++ c opencv visual-studio-2012


【解决方案1】:

根据聊天中的讨论,事实证明 OP 链接的是 OpenCV 2.4.10 而不是 OpenCV 3.0。

通过更正链接库,问题得到解决。

【讨论】:

    猜你喜欢
    • 2017-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-13
    • 2020-11-21
    相关资源
    最近更新 更多