title: Why should I link GNU C++ Standard Library (libstdc++) when invoking opencv library on mac?
body: <p>In many cases invoking opencv library also needs to invoke GNU C++ Standard Library (libstd++) on mac as <a href="http://www.theworldneedsmoredreamers.net/using-opencv-2-with-os-x-hello-world/" rel="nofollow noreferrer">this post</a> shows. Probably this is because the compiled opencv library need the support of GNU libstd++. However, as <a href="https://stackoverflow.com/questions/19634803/link-different-c-standard-libraries-on-mac-os-x">this pos</a>t shows, LLVM C++ Standard Library (libc++) is more promising in the future. Therefore, I decide to compile the opencv library from the source code and make a library that does not rely on libstd++ but rather it needs libc++. </p>
  
  <p>The opencv library I am using is 2.4.8, and I build the static OPENCV library. The cmake script in opencv that is related to stdc++ is </p>
  
  <pre><code>set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} stdc++)
  </code></pre>
  
  <p>, which is in OpenCVCompilerOptions.cmake file. In order to make sure that opencv will not use libstd++ but libc++, I changed it to </p>
  
  <pre><code>set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} c++)
  </code></pre>
  
  <p>When a Xcode was built with CMake, I also check the <code>CMakeCache.txt</code> file, which contains the link options for the project. I can clearly observe that libstd++ is not needed any more. For example, the <code>opencv_core</code> library: </p>
  
  <pre><code>//Dependencies for the target
  opencv_core_LIB_DEPENDS:STATIC=general;zlib;general;c++;
  </code></pre>
  
  <p>However, when I invoke the opencv library from an application, it seems that libstd++ must be invoked in the meantime, otherwise I have the following error messages:</p>
  
  <pre><code> Undefined symbols for architecture x86_64:
    "std::basic_string&lt;wchar_t, std::char_traits&lt;wchar_t&gt;, std::allocator&lt;wchar_t&gt; &gt;::size() const", referenced from:
        cv::fromUtf16(std::basic_string&lt;wchar_t, std::char_traits&lt;wchar_t&gt;, std::allocator&lt;wchar_t&gt; &gt; const&amp;) in libopencv_core.a(persistence.o)
    "std::basic_string&lt;wchar_t, std::char_traits&lt;wchar_t&gt;, std::allocator&lt;wchar_t&gt; &gt;::c_str() const", referenced from:
        cv::fromUtf16(std::basic_string&lt;wchar_t, std::char_traits&lt;wchar_t&gt;, std::allocator&lt;wchar_t&gt; &gt; const&amp;) in libopencv_core.a(persistence.o)
    "std::string::size() const", referenced from:
        cv::Exception::formatMessage() in libopencv_core.a(system.o)
        cv::error(cv::Exception const&amp;) in libopencv_core.a(system.o)
        cv::tempfile(char const*) in libopencv_core.a(system.o)
        cv::FileStorage::getDefaultObjectName(std::string const&amp;) in libopencv_core.a(persistence.o)
        cv::toUtf16(std::string const&amp;) in libopencv_core.a(persistence.o)
        cv::operator&lt;&lt;(cv::FileStorage&amp;, std::string const&amp;) in libopencv_core.a(persistence.o)
        cv::write(cv::FileStorage&amp;, std::string const&amp;, std::string const&amp;) in libopencv_core.a(persistence.o)
        ...
    "std::string::c_str() const", referenced from:
  </code></pre>
  
  <p>Any ideas on how to prepare the opencv library so that the libstd++ is not needed? Thanks. </p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>I tried to let opencv picks up the native one by using the following cmake command:</p>
  
  <pre><code> set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS})
  </code></pre>
  
  <p>However, it seems that opencv always picks up libstd++. </p>