title: Apple Mach-O linker and multiple "undefined symbols" error using OpenCV
body: <p>I am currently a real beginner in Objective C, and I am developing an app using the framework OpenCV.</p>
  
  <p>I am following a tutorial, but while builing the project, I got several errors :</p>
  
  <pre><code>Undefined symbols for architecture i386:
    "std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;::flush()", referenced from:
        cv::gpu::error(char const*, char const*, int, char const*) in opencv2(gpumat.o)
    "std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;::sentry::sentry(std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;)", referenced from:
        std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp; std::__1::operator&lt;&lt; &lt;std::__1::char_traits&lt;char&gt; &gt;(std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;, char const*) in opencv2(gpumat.o)
    "std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;::sentry::~sentry()", referenced from:
        std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp; std::__1::operator&lt;&lt; &lt;std::__1::char_traits&lt;char&gt; &gt;(std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;, char const*) in opencv2(gpumat.o)
    "std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;::operator&lt;&lt;(int)", referenced from:
        cv::gpu::error(char const*, char const*, int, char const*) in opencv2(gpumat.o)
    "std::__1::cerr", referenced from:
        cv::gpu::error(char const*, char const*, int, char const*) in opencv2(gpumat.o)
    "std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from:
        std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp; std::__1::operator&lt;&lt; &lt;std::__1::char_traits&lt;char&gt; &gt;(std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;, char const*) in opencv2(gpumat.o)
    "std::__1::ios_base::clear(unsigned int)", referenced from:
        std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp; std::__1::operator&lt;&lt; &lt;std::__1::char_traits&lt;char&gt; &gt;(std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;, char const*) in opencv2(gpumat.o)
    "std::__1::__vector_base_common&lt;true&gt;::__throw_length_error() const", referenced from:
        __ZNSt3__16vectorImNS_9allocatorImEEE6assignIPmEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeES7_S7_ in opencv2(matrix.o)
        std::__1::vector&lt;unsigned long, std::__1::allocator&lt;unsigned long&gt; &gt;::vector(unsigned long) in opencv2(matrix.o)
        std::__1::vector&lt;unsigned long, std::__1::allocator&lt;unsigned long&gt; &gt;::__append(unsigned long) in opencv2(matrix.o)
        std::__1::vector&lt;cv::Vec&lt;float, 2&gt;, std::__1::allocator&lt;cv::Vec&lt;float, 2&gt; &gt; &gt;::vector(unsigned long) in opencv2(matrix.o)
        std::__1::vector&lt;int, std::__1::allocator&lt;int&gt; &gt;::vector(unsigned long) in opencv2(matrix.o)
        std::__1::vector&lt;cv::Vec&lt;int, 128&gt;, std::__1::allocator&lt;cv::Vec&lt;int, 128&gt; &gt; &gt;::__append(unsigned long) in opencv2(matrix.o)
        std::__1::vector&lt;cv::Vec&lt;int, 64&gt;, std::__1::allocator&lt;cv::Vec&lt;int, 64&gt; &gt; &gt;::__append(unsigned long) in opencv2(matrix.o)
        ...
    "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::__init(char const*, unsigned long)", referenced from:
        cv::Mat::create(int, int const*, int) in opencv2(matrix.o)
        __ZN2cvL7setSizeERNS_3MatEiPKiPKmb in opencv2(matrix.o)
        cv::Mat::Mat(cv::Mat const&amp;, cv::Range const&amp;, cv::Range const&amp;) in opencv2(matrix.o)
        cv::Mat::Mat(cv::Mat const&amp;, cv::Rect_&lt;int&gt; const&amp;) in opencv2(matrix.o)
        cv::Mat::Mat(cv::Mat const&amp;, cv::Range const*) in opencv2(matrix.o)
        cv::Mat::diag(int) const in opencv2(matrix.o)
        cv::Mat::Mat(_IplImage const*, bool) in opencv2(matrix.o)
        ...
    "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::~basic_string()", referenced from:
        cv::Mat::create(int, int const*, int) in opencv2(matrix.o)
        __ZN2cvL7setSizeERNS_3MatEiPKiPKmb in opencv2(matrix.o)
        cv::Mat::Mat(cv::Mat const&amp;, cv::Range const&amp;, cv::Range const&amp;) in opencv2(matrix.o)
        cv::Mat::Mat(cv::Mat const&amp;, cv::Rect_&lt;int&gt; const&amp;) in opencv2(matrix.o)
        cv::Mat::Mat(cv::Mat const&amp;, cv::Range const*) in opencv2(matrix.o)
        cv::Mat::diag(int) const in opencv2(matrix.o)
        cv::Mat::Mat(_IplImage const*, bool) in opencv2(matrix.o)
        ...
    "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::resize(unsigned long, char)", referenced from:
        __ZL8icvCloseP13CvFileStoragePNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE in opencv2(persistence.o)
    "std::__1::basic_string&lt;wchar_t, std::__1::char_traits&lt;wchar_t&gt;, std::__1::allocator&lt;wchar_t&gt; &gt;::__init(wchar_t const*, unsigned long)", referenced from:
        cv::toUtf16(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;) in opencv2(persistence.o)
    "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::__init(char const*, unsigned long, unsigned long)", referenced from:
        std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; std::__1::operator+&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, char const*) in opencv2(system.o)
    "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::append(char const*)", referenced from:
        cv::tempfile(char const*) in opencv2(system.o)
    "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::append(char const*, unsigned long)", referenced from:
        std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; std::__1::operator+&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, char const*) in opencv2(system.o)
    "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::assign(char const*)", referenced from:
        cv::tempfile(char const*) in opencv2(system.o)
    "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::basic_string(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;)", referenced from:
        cv::Exception::Exception(int, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, int) in opencv2(system.o)
        cv::tempfile(char const*) in opencv2(system.o)
        cv::Exception::Exception(cv::Exception const&amp;) in opencv2(system.o)
        cv::operator&lt;&lt;(cv::FileStorage&amp;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;) in opencv2(persistence.o)
    "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::operator=(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;)", referenced from:
        cv::Exception::formatMessage() in opencv2(system.o)
        cv::tempfile(char const*) in opencv2(system.o)
        cv::operator&lt;&lt;(cv::FileStorage&amp;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;) in opencv2(persistence.o)
  ld: symbol(s) not found for architecture i386
  
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>I am sure that the problem comes from the framework, but not the framework itself, but how it is link in the project, or...</p>
  
  <p>I precise that I've linked it that way in the .pch file</p>
  
  <pre><code> #import &lt;Availability.h&gt;
  
  #ifndef __IPHONE_5_0
  #warning "This project uses features only available in iOS SDK 5.0 and later."
  #endif
  
  #ifdef __cplusplus
  #import &lt;opencv2/opencv.hpp&gt;
  #endif
  
  #ifdef __OBJC__
      #import &lt;UIKit/UIKit.h&gt;
      #import &lt;Foundation/Foundation.h&gt;
  #endif
  </code></pre>
  
  <p>Don't really know what to do..</p>
  
  <p>EDIT : forgot to tell that I renamed my .m file to .mm and my .h file to .hh
  Is there anything else we need to do to get an objective C++ projet ?</p>