CMake cannot find OpenMP

2019-04-04 19:11发布

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

find_package(OpenMP REQUIRED)

and CMake errors out with

CMake Error at /opt/ros/groovy/share/catkin/cmake/catkinConfig.cmake:72 (find_package):
  Could not find a configuration file for package openmp.

  Set openmp_DIR to the directory containing a CMake configuration file for
  openmp.  The file will have one of the following names:

    openmpConfig.cmake
    openmp-config.cmake

Checking my filesystem, I see that I have /usr/share/cmake-2.8/Modules/FindOpenMP.cmake but no openmpConfig.cmake or openmp-config.cmake. What do I need to do to fix this?

标签: cmake openmp
2条回答
啃猪蹄的小仙女
2楼-- · 2019-04-04 19:54

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()
查看更多
地球回转人心会变
3楼-- · 2019-04-04 19:58

OpenMp is not a package, if it's supported, it comes as a part of the your compiler. Try setting CMAKE_C_FLAGS or CMAKE_CXX_FLAGS accordingly. e.g:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp") activates OpenMP for compiling C sources when gcc is used. For other compilers, you should first detect the compiler and then add appropriate flags

查看更多
登录 后发表回答