c++ 缺少:OpenMP_C_标志OpenMP_C_库_名称

vdgimpew  于 2022-12-20  发布在  其他
关注(0)|答案(5)|浏览(234)

我在Mac OSX上使用OpenMP编译一个项目时遇到了困难。错误是:

CMake Error at /usr/local/Cellar/cmake/3.10.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
Call stack most recent call first) 
/usr/local/Cellar/cmake/3.10.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.10.2/share/cmake/Modules/FindOpenMP.cmake:447 (find_package_handle_standard_args)
libRORPO/CMakeLists.txt:7 (find_package)

与在项目中搜索OpenMP关联的CMakeLists文件如下:

# RORPO Lib

project(libRORPO)
cmake_minimum_required(VERSION 2.8)

# FIND OPENMP
find_package( OpenMP REQUIRED)
if(OPENMP_FOUND)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} 
         ${OpenMP_EXE_LINKER_FLAGS}")
endif()

# ADD FILES
file(GLOB_RECURSE RORPO_HEADERS *.hpp *.h)
file(GLOB_RECURSE RORPO_SOURCES *.c)

add_library(RORPO ${LIB_TYPE} ${RORPO_SOURCES} ${RORPO_HEADERS})

install( FILES ${RORPO_HEADERS} DESTINATION include/libRORPO)
install( TARGETS RORPO DESTINATION lib)

我使用gcc-7和Clang-omp验证了OpenMP安装是否运行良好。我搜索了类似的错误。响应指出,cmake中有一个最新的软件包,允许查找OpenMP。我重新安装了CMAKE以获得最新版本,但它仍然不工作。我不是cmake配置Maven......如果您能指导我,我将不胜感激。

rhfm7lfc

rhfm7lfc1#

这是因为Xcode不支持clang,请使用系统clang。
方法1:设置env变量,然后运行cmake https://gist.github.com/svenevs/f00ed3898d2af6248921b63254aa8cc1

export CC=/usr/local/opt/llvm/bin/clang
export CXX=/usr/local/opt/llvm/bin/clang++
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"

方法2:在CMakeLists.txt中设置环境变量

message(STATUS "set env var")
set(ENV{CC} "/usr/local/opt/llvm/bin/clang")
set(ENV{CXX} "/usr/local/opt/llvm/bin/clang++")
set(ENV{LDFLAGS} "-L/usr/local/opt/llvm/lib")
set(ENV{CPPFLAGS} "-I/usr/local/opt/llvm/include")

方法3:更改CMakeLists.txt中的变量

message(STATUS "set compipler")
set(CMAKE_C_COMPILER "/usr/local/Cellar/llvm/5.0.1/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/5.0.1/bin/clang++")
set(OPENMP_LIBRARIES "/usr/local/Cellar/llvm/5.0.1/lib")
set(OPENMP_INCLUDES "/usr/local/Cellar/llvm/5.0.1/include")

set(OPENMP_LIBRARIES "/usr/local/opt/llvm/lib")
link_directories(${OPENMP_LIBRARIES})

方法4.运行cmake时更改env变量

cmake .. -DCC=xxx -DCXX=xxx -DLDFLAGS="" -DCPPFLAGS=""
kd3sttzy

kd3sttzy2#

我在基于ARM的MacOS机器上遇到了这个问题,安装libomp后修复了它:

arch -x86_64 brew install libomp
yruzcnhs

yruzcnhs3#

查找OpenMP

尽管到目前为止有其他的答案,但是可以使用系统编译器。

if(APPLE)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
    set(OpenMP_C "${CMAKE_C_COMPILER}" CACHE STRING "" FORCE)
    set(OpenMP_C_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument" CACHE STRING "" FORCE)
    set(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5" CACHE STRING "" FORCE)
    set(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
    set(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
    set(OpenMP_libiomp5_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  set(OpenMP_CXX "${CMAKE_CXX_COMPILER}" CACHE STRING "" FORCE)
  set(OpenMP_CXX_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument" CACHE STRING "" FORCE)
  set(OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp5" CACHE STRING "" FORCE)
  set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
  set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
  set(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
endif()
endif()
lmvvr0a8

lmvvr0a84#

我发现了一个解决方案,建议:http://stechschulte.net/2016/03/20/openmp-osx-cmake.html
诀窍在于cmake必须在CC和CXX环境变量指向clang-omp的情况下运行:

CC=clang-omp CXX=clang-omp++ cmake

请注意,clang-omp和clang-omp++必须在安装llvm后通过以下方式定义:

brew install llvm

并创建两个符号链接:

ln -s /usr/local/opt/llvm/bin/clang /usr/local/bin/clang-omp
ln -s /usr/local/opt/llvm/bin/clang++ /usr/local/bin/clang-omp++
ghhaqwfi

ghhaqwfi5#

使用@lbsweek提示:
在Mapbrew安装llvm的位置后,它对我起作用了。
即“/opt/自制程序/Cellar/llvm/{版本}”
一旦知道它,您就可以将OpenMP_C_FLAGS OpenMP_C_LIB_NAMESMap为:

export CC=/opt/homebrew/Cellar/llvm/15.0.6/bin/clang
export CXX=/opt/homebrew/Cellar/llvm/15.0.6/bin/clang++
export LDFLAGS="-L/opt/homebrew/Cellar/llvm/15.0.6/lib"
export CPPFLAGS="-I/opt/homebrew/Cellar/llvm/15.0.6/include"

相关问题