0
votes

I've just started with OpenCV and was going through some basic sample programs when I received a linking error. Everything should be part of the core library libopencv_core.2.4.3.dylib, which is appropriately linked (no problems with the Mat objects, just the formatter class from operations.hpp).

In addition, if the line: cout << format(M,"C") << endl; is excluded, then the code compiles fine but there is an odd behaviour. Once the M Mat-object is sent to cout, the values contained in the object don't print and subsequent calls to cout yield nothing, even though the code runs to completion.

Has anyone else had this issue?

openCV 2.4.3 from macports, xcode 4.5.2, os x Lion 10.7.5

Code: (effectively a snippet of cout_mat.cpp from openCV sample code)

    #include "/usr/local/include/opencv2/opencv.hpp"
    #include "/usr/local/include/opencv2/core/operations.hpp"
    #include <iostream>


    using namespace cv;
    using namespace std;


int main(int,char**)
{

    Mat M = Mat::eye(4, 4, CV_64F);
    M.at<double>(0,0) = CV_PI;

    // print out val at 0,0
    cout << "M(0,0) = " << M.at<double>(0,0) << endl;

    // test serial out capabilities of cv::Mat (yields no output beyond M=)
    cout << "M = " << endl << M << endl;
    // try to print M(0,0) to screen again to demonstrate that cout no longer prints to screen
    cout << "M(0,0) = " << M.at<double>(0,0) << endl;
    // Try to format the output with 'c-style',  Note: if included in program this line yields linker error
    cout << format(M,"C") << endl;


    return 0;
}

output in debugger: with line "cout << format(M,"C") << endl;" commented out

M(0,0) = 3.14159
M = 

M= is empty along with additional cout for: M(0,0) = 3.14159

error with line "cout << format(M,"C") << endl;" included:

Undefined symbols for architecture x86_64:
  "cv::Formatted::Formatted(cv::Mat const&, cv::Formatter const*, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
      __ZN2cvL6formatERKNS_3MatEPKcRKNSt3__16vectorIiNS5_9allocatorIiEEEE in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
1
It looks like a Mac specific issue, you could change your compiler from Clang to GCC, and try.tomriddle_1234
@tomriddle_1234 - great suggestion. Switching from Apple LLVM compiler 4.1 to LLVM gcc 4.2 fixed both issues!amclean

1 Answers

0
votes

tomriddle_1234's suggestion fixed my both problems.

Under Project -> Build Settings -> Build Options -> Compiler for c++/objective-c/c: select LLVM gcc 4.2 in place of the Apple LLVM 4.1.

Now, the cout appropriately displays all entries and the format function works as well without giving a linker error.