I have a C++
project that is implemented in Linux with JetBrain CLion
IDE. To get the executable, I used CMake
which is fully matched with JetBrain CLion
. The project uses MPI
to handle multi-node processing, and the project works fine in Linux.
Now, I have to get an executable for Windows too. So, I installed the community version of Visual Studio 2019
along with Microsft MPI
to build my project there too. I found that it might be easier to create the sln
file for the project by CMake
and then import the project into VS
. But, when I tried this approach, I got an error for not finding MPI
:
Could NOT find MPI_C (missing: MPI_C_LIB_NAMES MPI_C_HEADER_DIR MPI_C_WORKS)
Could NOT find MPI_CXX (missing: MPI_CXX_LIB_NAMES MPI_CXX_HEADER_DIR MPI_CXX_WORKS)
CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find MPI (missing: MPI_C_FOUND MPI_CXX_FOUND)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.15/Modules/FindMPI.cmake:1687 (find_package_handle_standard_args)
CMakeLists.txt:35 (find_package)
The cmake code that works in Linux is:
find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
add_executable(prjt main.cpp)
add_subdirectory(sub1)
add_subdirectory(sub2)
target_link_libraries(prjt ${MPI_LIBRARIES})
set_property(TARGET prjt PROPERTY CXX_STANDARD 11)
After reading [1] and [2], I also tried:
set(CMAKE_PREFIX_PATH "C:/Program Files/Microsoft MPI")
find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
set(CMAKE_C_FLAGS "${CMAKE_FLAGS} ${MPI_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_EXE_LINKER_FLAGS}")
add_executable(prjt main.cpp)
add_subdirectory(sub1)
add_subdirectory(sub2)
target_link_libraries(prjt ${MPI_LIBRARIES})
set_property(TARGET prjt PROPERTY CXX_STANDARD 11)
but still no success.
I also tried to link MPI directly via MSVS, as it is instructed in [3], but it did not work too. The problem within that approach is that when I call set MSMPI
, I only get MSMPI_BIN=C:\Program Files\Microsoft MPI\Bin\
and I do not get the rest of the environment variables. In the Linker
of MSVS
also I manually added the Microst SDK
address. (I also added the other required environment variables as [4] explains)
I appreciate any help or comment.