我在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配置专家..如果你能引导我,我将不胜感激。
答案 0 :(得分:1)
我找到了一个解决方案:http://stechschulte.net/2016/03/20/openmp-osx-cmake.html
诀窍是cmake必须在CC和CXX环境变量指向clang-omp的情况下运行:
CC=clang-omp CXX=clang-omp++ cmake
请注意,必须在安装llvm后定义clang-omp和clang-omp ++:
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++
答案 1 :(得分:1)
itemOffered
答案 2 :(得分:0)
这是因为不支持Xcode叮当声,请改用系统叮当声。
方法1:设置环境变量,然后运行cmake https://gist.github.com/svenevs/f00ed3898d2af6248921b63254aa8cc1export 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中更改var
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=""