我正在尝试将MPI包含在项目中,并将其作为导入库添加到我的CMake项目中。这是我的代码:
find_package(MPI REQUIRED)
add_library(MPI SHARED IMPORTED)
set_property(TARGET MPI PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${MPI_INCLUDE_PATH})
set_property(TARGET MPI PROPERTY IMPORTED_LOCATION ${MPI_CXX_LIBRARIES})
这给了我以下错误:
clang: error: no such file or directory: '/usr/local/Cellar/open-mpi/1.10.2_1/lib/libmpi_cxx.dylib;/usr/local/Cellar/open-mpi/1.10.2_1/lib/libmpi.dylib'
我认为这是因为IMPORTED_LOCATION
只是一个文件而不是FindMPI.cmake
返回的文件。任何想法如何解决这个问题?
答案 0 :(得分:1)
将列表中的第一个元素用作 IMPORTED_LOCATION 属性,将其他元素用作 INTERFACE_LINK_LIBRARIES 属性:
find_package(MPI REQUIRED)
add_library(MPI SHARED IMPORTED)
set_property(TARGET MPI PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${MPI_INCLUDE_PATH})
# Copy list for prevent its from modification.
set(other_elems ${MPI_CXX_LIBRARIES})
list(GET other_elems 0 first_elem)
list(REMOVE_AT other_elems 0)
set_property(TARGET MPI PROPERTY IMPORTED_LOCATION ${first_elem})
set_property(TARGET MPI PROPERTY INTERFACE_LINK_LIBRARIES ${other_elems})