2

Problem

I am trying to get OpenCV up and running, but I ran into the same problem as this guy and this guy - I get linker errors when trying to build the project with the C++ interface, but with C interface the project builds.

In the second link, the answer is "You're mixing different implementations of STL. VC10 (for OpenCV) and STLPort (for your code)."

How can I make sure that I am only using VC10? (or later versions)

C style (Project builds successfully)

I am using Visual Studio 2012 and 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++ style (Project does not build)

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.
}

Errors:

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

Include and lib path settings in VS

  • C/C++/General/Additional Include Directories: C:\opencv\build\include
  • Linker/General/Additional Library Directories: \n C:\opencv\build\x86\vc11\lib
  • Linker/Input/Additional Dependencies: 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
Community
  • 1
  • 1
Nicolai Lissau
  • 7,298
  • 5
  • 43
  • 57
  • Can you show your `#include`? And your library path? – Miki Oct 13 '15 at 12:33
  • I added the changes I have made to the solution properties – Nicolai Lissau Oct 13 '15 at 12:40
  • @Attaque I'm pretty sure you don't mean the [tag:stl], removed the tag. Please read the tag wiki before adding it next time. Also you should change the text in your question and refer to the c++ standard library instead. – πάντα ῥεῖ Oct 13 '15 at 12:42
  • I apologize. Since it was based on the other questions I linked, I did not think about it too much. This might be part of the problem, I have not had the need to use a different library than what is provided with VS. Could you maybe do the change? – Nicolai Lissau Oct 13 '15 at 12:54
  • as soon as your VS project is 32 bit, this should work – Miki Oct 13 '15 at 13:02
  • I completely agree Miki :) Unfortunately.. I can send the project to you if you would like give it a run? – Nicolai Lissau Oct 13 '15 at 13:05
  • @Attaque static or dynamic libs? I try setting up a new VS12 project – Miki Oct 13 '15 at 13:11
  • dynamic. I followed this: http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html – Nicolai Lissau Oct 13 '15 at 13:16
  • works ok for me.. well, you're missing a waitKey(); in your C++ code, but that's not the issue here – Miki Oct 13 '15 at 13:22
  • I have no idea how to fix this then. Is it a problem that i have both vs12 and vs15 installed? – Nicolai Lissau Oct 13 '15 at 13:26
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92149/discussion-between-attaque-and-miki). – Nicolai Lissau Oct 13 '15 at 13:30

1 Answers1

1

From the discussion in chat, it turns out that the OP was linking against OpenCV 2.4.10 instead of OpenCV 3.0.

By correcting the linked libraries the issue is solved.

Miki
  • 40,887
  • 13
  • 123
  • 202