mac上使用g++编译出错“Undefined symbols for architecture x86_64:” 错误解决办法

        搞了一下午,终于找到答案了!!再Mac上使用自带的g++编译使用opencv编写的图像代码,在使用图像数据结构时,使用IplImage和CvMat数据类型进行简单的加载、显示图像和两种数据的相互转换都没有错误,但只要使用Mat数据结构就出现下面的错误:

Undefined symbols for architecture x86_64:\
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced from:\
      _main in main.o\
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:\
      _main in main.o\
  "std::terminate()", referenced from:\
      ___clang_call_terminate in main.o\
  "___cxa_begin_catch", referenced from:\
      ___clang_call_terminate in main.o\
  "___gxx_personality_v0", referenced from:\
      _main in main.o\
      Dwarf Exception Unwind Info (__eh_frame) 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)\
make: *** [main] Error 1\

想了很多办法,终于看到有人提示:编译选项添加-lstdc++,即使用标准C++库,问题解决!

-------------------------------------------------------------------------------------------------------------------------

    机器视觉群 :454254462 ,欢迎加入,进行算法研究!
    AR/VR群 :244751474 ,欢迎加入,进行项目讨论!

你可能感兴趣的:(C++,错误,x86_64)