gpt4 book ai didi

c++ - cmake3 : set path to mpi headers

转载 作者:行者123 更新时间:2023-11-28 04:12:56 25 4
gpt4 key购买 nike

基于 CMake: set path to MPI headers and binaries manually ,我将我的 cmake 文件设置为:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(TARGET "test")
PROJECT(${TARGET})
add_compile_options(-std=c++11)
set(CMAKE_CXX_FLAGS "-std=c++11" CACHE STRING "compile flags" FORCE)

find_package(MPI REQUIRED)
if (MPI_FOUND)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
else (MPI_FOUND)
message(SEND_ERROR "couldn't find MPI")
endif (MPI_FOUND)
add_executable(${TARGET} somefiles)
target_link_libraries(${TARGET} ${MPI_LIBRARIES})

而且效果很好。但是当我用 cmake3 做的时候:

CMAKE_MINIMUM_REQUIRED(VERSION 3.13.4)
the rest is the same as above

我收到这个错误:

CMake Error at /home/nourisaj/c++/WP1/build/CMakeFiles/CMakeTmp/cmTC_3d1ffTargets.cmake:16 (add_library):
Target "MPI::MPI_C" links to item " -Wl,-rpath -Wl,/usr/lib64/openmpi/lib
-Wl,--enable-new-dtags" which has leading or trailing whitespace. This is
now an error according to policy CMP0004.
Call Stack (most recent call first):
/home/nourisaj/c++/WP1/build/CMakeFiles/CMakeTmp/CMakeLists.txt:14 (include)


CMake Error at /home/nourisaj/c++/WP1/build/CMakeFiles/CMakeTmp/cmTC_3d1ffTargets.cmake:16 (add_library):
Target "MPI::MPI_C" links to item " -Wl,-rpath -Wl,/usr/lib64/openmpi/lib
-Wl,--enable-new-dtags" which has leading or trailing whitespace. This is
now an error according to policy CMP0004.
Call Stack (most recent call first):
/home/nourisaj/c++/WP1/build/CMakeFiles/CMakeTmp/CMakeLists.txt:14 (include)


CMake Error at /usr/share/cmake3/Modules/FindMPI.cmake:1187 (try_compile):
Failed to generate test project build system.
Call Stack (most recent call first):
/usr/share/cmake3/Modules/FindMPI.cmake:1228 (_MPI_try_staged_settings)
/usr/share/cmake3/Modules/FindMPI.cmake:1488 (_MPI_check_lang_works)
CMakeLists.txt:19 (find_package)

有什么想法吗?

最佳答案

您正在遇到 CMP0004政策错误。在早期版本的 CMake 中,链接库会自动删除所有前导或尾随空格。在某些情况下,这可能会导致微妙的、不希望出现的错误,因此 CMake 现在强制执行此策略,NEW 行为要求链接库有 no 前导或尾随空格。看起来您的 MPI 目标之一正在与此链接,它具有前导空白字符:

" -Wl,-rpath -Wl,/usr/lib64/openmpi/lib -Wl,--enable-new-dtags"

基于此 CMake issue ,此策略错误似乎已从 CMake 3.9 开始修复。如果您运行的 CMake 早于 3.9,您必须自己修改 FindMPI.cmake 文件以删除前导空格,或者您可以告诉 CMake 使用此策略的旧行为(静默删除前导空格):

cmake_policy(SET CMP0004 OLD)

这是 cmake_policy 的文档.虽然在 FindMPI.cmake 文件中设置此策略可能有效,但不建议这样做。实现 CMake 策略是为了避免 OLD 行为,因此建议您手动从文件中删除空格。

注意:与使用不同版本的 CMake 进行测试时的情况一样,确保在切换版本时删除 CMake 缓存并从头开始构建。

关于c++ - cmake3 : set path to mpi headers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57290410/

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