4

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.

5
  • You cannot have whitespace in the CMAKE_PREFIX_PATH string. Try set(CMAKE_PREFIX_PATH "C:/Program\ Files/Microsoft\ MPI"). Commented Jun 27, 2019 at 0:43
  • @kanstar I tried that and still same error. Commented Jun 27, 2019 at 13:11
  • 1
    The path you provide in CMAKE_PREFIX_PATH must contain a file called MPIConfig.cmake or MPI-config.cmake. Otherwise find_package won't find the package. So make sure to point to the directory where one of those are present. Commented Jun 27, 2019 at 19:34
  • @kanstar I checked all directories and neither of them contains either MPIConfig.cmake or MPI-config.cmake. I install MS-MPI v10.0 Is there anything that I need to install? Commented Jun 27, 2019 at 19:49
  • 1
    So, I think MPI is not shipped with a config file. But CMake ships already with a FindMPI.cmake file. Read the documentation of the file to get a grasp on what variables are defined. Commented Jun 27, 2019 at 20:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.