[CMake] MPI: Undefined symbol
Rafael Sadowski
rafael at sizeofvoid.org
Mon Aug 20 11:49:03 EDT 2018
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>.
> 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
More information about the CMake
mailing list