我正在尝试用OpenMP编译。我的CMakeLists.txt包含下面这行
find_package(OpenMP REQUIRED)
和CMake错误的输出
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检查我的文件系统,我看到我有/usr/share/cmake-2.8/Modules/FindOpenMP.cmake,但没有openmpConfig.cmake或openmp-config.cmake。我需要做些什么来解决这个问题?
发布于 2013-07-14 03:40:38
OpenMp不是一个包,如果它被支持,它将作为你的编译器的一部分。尝试相应地设置CMAKE_C_FLAGS或CMAKE_CXX_FLAGS。例如:
当使用gcc时,set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")激活OpenMP以编译C源代码。对于其他编译器,您应该首先检测编译器,然后添加适当的标志
发布于 2015-03-01 18:42:04
即使在2.x版本中,CMake也有一个FindOpenMP模块。请参阅http://www.cmake.org/cmake/help/v3.0/module/FindOpenMP.html
因此,我将这样做:
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()发布于 2021-05-11 20:52:28
根据Modern CMake online手册,以下是使用CMake配置OpenMP支持的方法:
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(MyTarget PUBLIC OpenMP::OpenMP_CXX)
endif()你绝对不应该手动添加像-fopenmp这样的标志(就像公认的答案建议的那样),因为这可能是不可移植的。
https://stackoverflow.com/questions/17633513
复制相似问题