This stackoverflow <https://stackoverflow.com/questions/23163075/how-to-compile-an-mpi-included-c-program-using-cmake/45485419#45485419> question might help you.
On Tue, Aug 21, 2018 at 4:52 AM Florian Lindner <mailingli...@xgm.de> wrote: > Hello, > > Am 20.08.18 um 17:49 schrieb Rafael Sadowski: > > On Mon Aug 20, 2018 at 04:24:07PM +0200, Florian Lindner wrote: > >> Hello, > >> > >> copied from a working MPI CMakeLists.txt: > >> > >> find_package(MPI REQUIRED) > > > > https://cmake.org/cmake/help/v3.0/module/FindMPI.html > > > > MPI_<lang>_FOUND TRUE if FindMPI found MPI flags for <lang> > > MPI_<lang>_COMPILER MPI Compiler wrapper for <lang> > > MPI_<lang>_COMPILE_FLAGS Compilation flags for MPI programs > > MPI_<lang>_INCLUDE_PATH Include path(s) for MPI header > > MPI_<lang>_LINK_FLAGS Linking flags for MPI programs > > MPI_<lang>_LIBRARIES All libraries to link MPI programs against > > > > Looks like you forgot <lang>. > > Should also work, versions without LANG are deprecated, but still > supported. > > But still, I didn't know about the new version and updated my cmake file, > but still getting the same error. > > find_package(MPI REQUIRED > COMPONENTS CXX) > include_directories(${MPI_CXX_INCLUDE_DIRS}) > set(COMPILE_OPTIONS ${COMPILE_FLAGS} ${MPI_CXX_COMPILE_OPTIONS}) > set(LINK_FLAGS ${LINK_FLAGS} ${MPI_CXX_LINK_FLAGS}) > add_definitions(${MPI_CXX_COMPILE_DEFINTIONS}) > > add_executable(StructureSolverParallel > "StructureSolver_Parallel/structureDataDisplay.cpp" > "StructureSolver_Parallel/StructureSolver.cpp" > "StructureSolver_Parallel/structureComputeSolution.cpp") > > target_link_libraries(StructureSolverParallel PUBLIC ${MPI_CXX_LBRARIES}) > > > [ 61%] Building CXX object > CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureComputeSolution.cpp.o > /usr/bin/c++ -I/home/lindnefn/precice/src -I/opt/mpich/include -Wall > -Wextra -Wno-unused-parameter -g -std=gnu++11 -o > CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureComputeSolution.cpp.o > -c > /home/lindnefn/devel/elastictube1d/StructureSolver_Parallel/structureComputeSolution.cpp > > [ 69%] Linking CXX executable StructureSolverParallel > /usr/bin/cmake -E cmake_link_script > CMakeFiles/StructureSolverParallel.dir/link.txt --verbose=1 > /usr/bin/c++ -Wall -Wextra -Wno-unused-parameter -g > > CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureDataDisplay.cpp.o > CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/StructureSolver.cpp.o > CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureComputeSolution.cpp.o > -o StructureSolverParallel /home/lindnefn/precice/build/last/libprecice.so > > /usr/bin/ld: > CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/StructureSolver.cpp.o: > undefined reference to symbol 'MPI_Init' > /usr/bin/ld: /opt/mpich/lib/libmpi.so.12: error adding symbols: DSO > missing from command line > > It doesn't seem to put the MPI_CXX_LIBRARIES at the end. Again, just > adding -lmpi to the final command does the trick. > > Putting message(${MPI_CXX_LIBRARIES}) after the MPI block returns: > > /opt/mpich/lib/libmpicxx.so/opt/mpich/lib/libmpi.so > > Any more ideas? > > Thanks, > Florian > > > > > >> include_directories(${MPI_INCLUDE_PATH}) > >> set(COMPILE_FLAGS ${COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}) > >> set(LINK_FLAGS ${LINK_FLAGS} ${MPI_LINK_FLAGS}) > >> > >> > >> add_executable(StructureSolverParallel > >> "StructureSolver_Parallel/structureDataDisplay.cpp" > >> "StructureSolver_Parallel/StructureSolver.cpp" > >> "StructureSolver_Parallel/structureComputeSolution.cpp") > >> > >> target_link_libraries(StructureSolverParallel PUBLIC ${PRECICE_LIBRARY}) > >> target_link_libraries(StructureSolverParallel PUBLIC ${MPI_LBRARIES}) > >> > >> configuration runs smooth: > >> > >> % cmake -DMPI_CXX_COMPILER=/opt/mpich/bin/mpicxx > -DMPI_C_COMPILER=/opt/mpich/bin/mpicc . && make > >> -- The CXX compiler identification is GNU 8.2.0 > >> [...] > >> -- Found MPI_CXX: /opt/mpich/lib/libmpicxx.so (found version "3.1") > >> -- Found MPI: TRUE (found version "3.1") > >> > >> make however: > >> > >> [ 69%] Linking CXX executable StructureSolverParallel > >> /usr/bin/cmake -E cmake_link_script > CMakeFiles/StructureSolverParallel.dir/link.txt --verbose=1 > >> /usr/bin/c++ -Wall -Wextra -Wno-unused-parameter -g > > CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureDataDisplay.cpp.o > CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/StructureSolver.cpp.o > CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureComputeSolution.cpp.o > -o StructureSolverParallel /home/lindnefn/precice/build/last/libprecice.so > >> /usr/bin/ld: > CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/StructureSolver.cpp.o: > undefined reference to symbol 'MPI_Init' > >> /usr/bin/ld: /opt/mpich/lib/libmpi.so.12: error adding symbols: DSO > missing from command line > >> > >> when I just take the last command line and -lmpi to it, it works. > >> > >> What could be missing there in CMakeLists? > >> > >> Thanks, > >> Florian > >> > >> -- > >> > >> Powered by www.kitware.com > >> > >> Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > >> > >> Kitware offers various services to support the CMake community. For > more information on each offering, please visit: > >> > >> CMake Support: http://cmake.org/cmake/help/support.html > >> CMake Consulting: http://cmake.org/cmake/help/consulting.html > >> CMake Training Courses: http://cmake.org/cmake/help/training.html > >> > >> Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > >> > >> Follow this link to subscribe/unsubscribe: > >> https://cmake.org/mailman/listinfo/cmake > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > https://cmake.org/mailman/listinfo/cmake > -- Best regards Haocheng Haocheng LIU Kitware, Inc. R&D Engineer 21 Corporate Drive Clifton Park, NY 12065-8662 Phone: 518-881-4421 <javascript:void(0);>
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake