gpt4 book ai didi

cmake - clang、openMP 和 CMake

转载 作者:行者123 更新时间:2023-12-03 01:39:21 26 4
gpt4 key购买 nike

我在使用 cmake 构建简单的 openMP 代码时遇到问题。

我已经安装了 clang-omp,并且可以使用 clang-omp -fopenmp filename.c 编译程序

我尝试了很多方法来制作 CMakeLists.txt 文件,但没有结果!在我包含的文件中:

FIND_PACKAGE( OpenMP REQUIRED)
if(OPENMP_FOUND)
message("OPENMP FOUND")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

我尝试通过调用告诉 CMake 使用该编译器:

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

和没有。

两种情况的结果如下:

-- Try OpenMP C flag = [-fopenmp=libomp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [ ]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [/openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-Qopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-xopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [+Oopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-qsmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-mp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-fopenmp=libomp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [ ]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [/openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-Qopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-xopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [+Oopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-qsmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-mp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find OpenMP (missing: OpenMP_C_FLAGS OpenMP_CXX_FLAGS)
Call Stack (most recent call first):
/Applications/CMake.app/Contents/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
/Applications/CMake.app/Contents/share/cmake-3.5/Modules/FindOpenMP.cmake:234 (find_package_handle_standard_args)
CMakeLists.txt:4 (FIND_PACKAGE)

最佳答案

添加非系统 clang(对我来说,LLVM 4.0)的问题是您必须添加 include 和 lib 目录。在我的例子中,llvm-config 正确地选择了它们,但 CMake 没有使用它们。

假设您的PATH没问题,并且您已经设置了CCCXX,您需要添加:

export C_INCLUDE_PATH=$(llvm-config --includedir)
export CPLUS_INCLUDE_PATH=$(llvm-config --includedir)
export LIBRARY_PATH=$(llvm-config --libdir)

如果您更喜欢 Lmod,这个 .lua 文件应该可以做到:

help([[
This is the module file for the llvm and clang compiler.
]])

local version = "4.0"

whatis("Name: LLVM")
whatis("Version: " .. version)
whatis("Keywords: System, Compiler")
whatis("URL: http://www.llvm.org/")
whatis("Description: LLVM compiler family")

family("compiler")

local prefix = "/work/llvm"

prepend_path("PATH", pathJoin(prefix, "bin"))
setenv("CC", pathJoin(prefix, "bin/clang"))
setenv("CXX", pathJoin(prefix, "bin/clang++"))
setenv("C_INCLUDE_PATH", pathJoin(prefix, "include"))
setenv("CPLUS_INCLUDE_PATH", pathJoin(prefix, "include"))
setenv("LIBRARY_PATH", pathJoin(prefix, "lib"))
prepend_path("DYLD_LIBRARY_PATH", pathJoin(prefix, "lib"))

(适用于 Mac,将 DYLD 更改为 LD 适用于 Linux)

这与 CMake 配合得很好,它会选择 -fopenmp。手动编译也只需要一个标志。

关于cmake - clang、openMP 和 CMake,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37969440/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com