【问题标题】:Issue installing openmp on mac using homebrew使用自制软件在 Mac 上安装 openmp 时出现问题
【发布时间】:2018-02-16 05:25:46
【问题描述】:

我正在尝试在我的 Mac 上使用 Openmp,但我遇到了一个我不理解的编译器错误。我使用

安装了openmp
brew install llvm

当我尝试使用 -fopenmp 编译我的代码时,我会收到类似这样的错误

Undefined symbols for architecture x86_64:
 "std::runtime_error::what() const", referenced from:
  vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::runtime_error> > in ccOEbbPM.o
  vtable for boost::exception_detail::error_info_injector<std::runtime_error> in ccOEbbPM.o
  vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::range_error> > in ccOEbbPM.o
  vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::overflow_error> > in ccOEbbPM.o
  vtable for boost::exception_detail::error_info_injector<std::range_error> in ccOEbbPM.o
  vtable for boost::exception_detail::error_info_injector<std::overflow_error> in ccOEbbPM.o
  "std::locale::operator==(std::locale const&) const", referenced from:
  boost::detail::lcast_put_unsigned<std::char_traits<char>, unsigned long long, char>::convert() in ccOEbbPM.o
 "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_first_not_of(char, unsigned long) const", referenced from:
  boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned long long> >::do_get_string[abi:cxx11](std::_Ios_Fmtflags, mpl_::bool_<false> const&) const in ccOEbbPM.o
 "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const", referenced from:
  std::basic_ostream<char, std::char_traits<char> >& boost::multiprecision::operator<< <boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned long long> >, (boost::multiprecision::expression_template_option)1>(std::basic_ostream<char, std::char_traits<char> >&, boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned long long> >, (boost::multiprecision::expression_template_option)1> const&) in ccOEbbPM.o

这只是错误代码的一小部分,因为它会持续很长时间,但如果需要,我会发布其余部分。我还安装了 boost 库。

感谢任何帮助,谢谢。

编辑:

导致错误的简单程序:

#include <iostream>
#include <omp.h>

using namespace std;

int main(){


int x = 5;



#pragma omp parallel
for(int y = 0; y < 50;y++){
  x += 5;
}

  cout <<  x << endl;
  return 0;
}

用于编译的命令:

gcc-7 -fopenmp -Wall ex.cc

gcc-7 -std=c++11 -fopenmp -Wall ex.cc (I get less errors doing it this way)

使用第二个编译命令时出错:

Undefined symbols for architecture x86_64:
  "std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)
(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
  _main in ccXt8Pa8.o
  "std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
  _main in ccXt8Pa8.o
  "std::ios_base::Init::Init()", referenced from:
  __static_initialization_and_destruction_0(int, int) in ccXt8Pa8.o
  "std::ios_base::Init::~Init()", referenced from:
  __static_initialization_and_destruction_0(int, int) in ccXt8Pa8.o
  "std::cout", referenced from:
  _main in ccXt8Pa8.o
  "std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
  _main in ccXt8Pa8.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

【问题讨论】:

  • 请显示可能导致错误的最简单的程序。另外,请显示您用来尝试编译它的命令。
  • 我用一个程序和使用的命令编辑了代码。
  • 使用g++-7,一切都会好起来的——毕竟是C++ ;-)
  • 哇,这么简单的解决方案,但它确实有效,谢谢,我很感激。
  • 没问题 - 我已经把它作为答案,这样人们以后就不必在 cmets 中到处乱找了。

标签: c++ openmp homebrew


【解决方案1】:

使用g++-7 而不是gcc-7,一切都会好起来的——毕竟是C++ ;-)

g++-7 -std=c++11 -fopenmp openmp.cpp -o openmp

【讨论】:

    猜你喜欢
    • 2022-08-17
    • 1970-01-01
    • 1970-01-01
    • 2021-04-18
    • 1970-01-01
    • 2013-12-23
    • 2013-10-14
    • 2019-12-20
    • 2015-04-23
    相关资源
    最近更新 更多