gpt4 book ai didi

c++ - 使用 Homebrew 软件在 Mac 上安装 openmp

转载 作者:行者123 更新时间:2023-11-30 05:04:35 25 4
gpt4 key购买 nike

我想在我的 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 而不是 gcc-7,一切都会好起来的——毕竟它是 C++ ;-)

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

关于c++ - 使用 Homebrew 软件在 Mac 上安装 openmp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48820554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com