在MacOS中使用OpenMP
2023-12-24 09:26:26 Author: itlanyan.com(查看原文) 阅读量:17 收藏

C/C++ MacOS2023年12月27日

CMake 3.9对 OpenMP 的支持有了很大的提升,但是根据Modern CMake中的教程,如下配置可能不会生效:

find_package(OpenMP)
if(OpenMP_CXX_FOUND)
    target_link_libraries(MyTarget PUBLIC OpenMP::OpenMP_CXX)
endif()

而是可能出现如下提示:

-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) 
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) 
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)

解决办法为:

1. 先安装 libomp

brew install libomp

2. 如果安装后再运行CMake无错误提示,那就直接可以用。如果还是报同样的错误,则需要继续设置环境变量:

export OpenMP_ROOT=$(brew --prefix)/opt/libomp

参考

  1. How to find OpenMP with clang on macOS

2. OpenMP simple C example with CMake


文章来源: https://itlanyan.com/using-openmp-on-macos/
如有侵权请联系:admin#unsafe.sh