CMake cannot find OpenMP

前端 未结 4 2025
南笙
南笙 2021-02-19 02:07

I am trying to compile with OpenMP. My CMakeLists.txt contains the line

find_package(OpenMP REQUIRED)

and CMake errors out with

4条回答
  •  青春惊慌失措
    2021-02-19 03:02

    CMake has a FindOpenMP module even in 2.x versions. See http://www.cmake.org/cmake/help/v3.0/module/FindOpenMP.html

    So I'll do this:

    OPTION (USE_OpenMP "Use OpenMP" ON)
    IF(USE_OpenMP)
      FIND_PACKAGE(OpenMP)
      IF(OPENMP_FOUND)
        SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
      ENDIF()
    ENDIF()
    

提交回复
热议问题