How can I install openMP on my new MacBook Pro (with Mac OS Catalina)?

后端 未结 2 665
予麋鹿
予麋鹿 2021-01-03 15:35

I installed Xcode (and also the command line tools) but terminal says (when I\'m compiling):

gcc -o task -fopenmp task.c
clang: error: unsupported option \'-         


        
2条回答
  •  [愿得一人]
    2021-01-03 16:26

    This https://iscinumpy.gitlab.io/post/omp-on-high-sierra/ suggest to do the following:

    brew install libomp
    

    To install the OpenMP runtime components/libraries.

    Then, when compiling:

    • use -Xpreprocessor -fopenmp in place of -fopenmp in the compile step (-c option)
    • add -lomp to the linking step

    Note that the above page also mention that CMake 3.12 or later will automatically find the right way of adding OpenMP on MacOS:

    cmake_minimum_required(VERSION 3.12)
    project(openmptest CXX)
    
    add_executable(sample sample.cpp)
    
    find_package(OpenMP REQUIRED)
    target_link_libraries(sample PRIVATE OpenMP::OpenMP_CXX)
    

    Note: I didn't test any of this but it sounds relatively sane

提交回复
热议问题