在mac上调用opencv库时,为什么要链接GNU C ++标准库(libstdc ++)?

时间:2015-08-26 09:01:37

标签: c++ xcode macos opencv

在许多情况下,调用opencv库也需要在this post显示的mac上调用GNU C ++标准库(libstd ++)。可能这是因为编译的opencv库需要GNU libstd ++的支持。但是,如this pos所示,LLVM C ++标准库(libc ++)在未来更有前途。因此,我决定从源代码编译opencv库,并创建一个不依赖于libstd ++的库,而是需要libc ++。

我使用的opencv库是2.4.8,我构建了静态OPENCV库。 opencv中与stdc ++相关的cmake脚本是

set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} stdc++)

,位于OpenCVCompilerOptions.cmake文件中。为了确保opencv不使用libstd ++而不是libc ++,我将其更改为

set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} c++)

当使用CMake构建Xcode时,我还会检查CMakeCache.txt文件,其中包含项目的链接选项。我可以清楚地看到不再需要libstd ++了。例如,opencv_core库:

//Dependencies for the target
opencv_core_LIB_DEPENDS:STATIC=general;zlib;general;c++;

但是,当我从应用程序调用opencv库时,似乎必须在此期间调用libstd ++,否则我会收到以下错误消息:

 Undefined symbols for architecture x86_64:
  "std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::size() const", referenced from:
      cv::fromUtf16(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) in libopencv_core.a(persistence.o)
  "std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::c_str() const", referenced from:
      cv::fromUtf16(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) 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&) in libopencv_core.a(system.o)
      cv::tempfile(char const*) in libopencv_core.a(system.o)
      cv::FileStorage::getDefaultObjectName(std::string const&) in libopencv_core.a(persistence.o)
      cv::toUtf16(std::string const&) in libopencv_core.a(persistence.o)
      cv::operator<<(cv::FileStorage&, std::string const&) in libopencv_core.a(persistence.o)
      cv::write(cv::FileStorage&, std::string const&, std::string const&) in libopencv_core.a(persistence.o)
      ...
  "std::string::c_str() const", referenced from:

关于如何准备opencv库以便不需要libstd ++的任何想法?谢谢。

修改

我尝试让opencv使用以下cmake命令获取本机:

 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS})

然而,似乎opencv总是选择libstd ++。

0 个答案:

没有答案