[CMake] MPI: Undefined symbol

Florian Lindner mailinglists at xgm.de
Mon Aug 20 10:24:07 EDT 2018


Hello,

copied from a working MPI CMakeLists.txt:

find_package(MPI REQUIRED)
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



More information about the CMake mailing list