CMake fails to find PETSc: undefined reference to symbol 'ompi_mpi_comm_self'

Issue #990 resolved
Johannes Ring created an issue

When trying to install DOLFIN on my laptop, CMake failed to detect PETSc. The problem was that it failed to run the test in FindPETSc.cmake. Here is the output from try_run:

/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_17e55.dir/link.txt --verbose=1                                                                                               
/usr/lib/ccache/c++       CMakeFiles/cmTC_17e55.dir/petsc_test_lib.cpp.o  -o cmTC_17e55 -Wl,-rpath,/usr/lib/petscdir/3.7.7/x86_64-linux-gnu-real/lib /usr/lib/petscdir/3.7.7/x86_64-linux-gnu-real/lib/libpetsc_real.so                                                                                                                                          
/usr/bin/ld: CMakeFiles/cmTC_17e55.dir/petsc_test_lib.cpp.o: undefined reference to symbol 'ompi_mpi_comm_self'                                                                  
//usr/lib/x86_64-linux-gnu/libmpi.so.20: error adding symbols: DSO missing from command line                                                                                     
collect2: error: ld returned 1 exit status

The problem is that it is not linking with the MPI library. The documentation for try_run says that any -DLINK_LIBRARIES=... value given to CMAKE_FLAGS will be ignored when using LINK_LIBRARIES. This means that CMAKE_REQUIRED_LIBRARIES is not being used. Adding this to LINK_LIBRARIES instead fixes the problem:

-    "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}"
-    LINK_LIBRARIES PETSC::petsc
+    LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} PETSC::petsc

I am using Debian unstable and the Debian PETSc package (version 3.7.7).

Comments (1)

  1. Log in to comment