Skip to content

Instantly share code, notes, and snippets.

@JM1
Last active July 10, 2019 08:36
Show Gist options
  • Save JM1/ccf093b23accf910effc49560de49a30 to your computer and use it in GitHub Desktop.
Save JM1/ccf093b23accf910effc49560de49a30 to your computer and use it in GitHub Desktop.
Fix linker errors with VTK-6.0 and MPICH

Fix linker errors with VTK-6.0 and MPICH

Suppose you build your C/C++ library using CMake and use find_package(VTK) to include VTK headers and libraries, at Ubuntu Trusty (14.04). You compile and link your code against another MPI implementation like MPICH, e.g. running cmake -DMPI_C_COMPILER=/usr/bin/mpicc.mpich -DMPI_CXX_COMPILER=/usr/bin/mpicxx.mpich ... You setup CMake to compile a C/C++ application and try to link it to your library. The linker will throw an error at one of your library-exported MPI functions, e.g.:

/usr/bin/ld: CMakeFiles/main.cpp.o: undefined reference to symbol 'ompi_mpi_comm_null'
//usr/lib/libmpi.so.1: error adding symbols: DSO missing from command line

VTK 6.0 at Ubuntu Trusty (14.04) is linked against OpenMPI. The CMake files installed in line with VTK (/usr/lib/cmake/vtk-6.0/Modules/vtkParallelMPI.cmake) add the OpenMPI header paths to your library's CMake include directories:

set(vtkParallelMPI_INCLUDE_DIRS "${VTK_INSTALL_PREFIX}/include/vtk-6.0;/usr/lib/openmpi/include;/usr/lib/openmpi/include/openmpi")

So your library uses OpenMPI headers instead of MPICH headers. You did not add VTK header paths and did not link libraries to your application within CMake and thus the linker is not able to resolve those referenced OpenMPI symbols. To workaround this, we patch the VTK CMake files and remove those OpenMPI includes.

--- a/usr/lib/cmake/vtk-6.0/Modules/vtkParallelMPI.cmake 2014-04-12 02:48:38.000000000 +0200
+++ b/usr/lib/cmake/vtk-6.0/Modules/vtkParallelMPI.cmake 2019-07-10 09:54:17.719813485 +0200
@@ -1,7 +1,7 @@
set(vtkParallelMPI_LOADED 1)
set(vtkParallelMPI_DEPENDS "vtkParallelCore")
set(vtkParallelMPI_LIBRARIES "vtkParallelMPI")
-set(vtkParallelMPI_INCLUDE_DIRS "${VTK_INSTALL_PREFIX}/include/vtk-6.0;/usr/lib/openmpi/include;/usr/lib/openmpi/include/openmpi")
+set(vtkParallelMPI_INCLUDE_DIRS "${VTK_INSTALL_PREFIX}/include/vtk-6.0")
set(vtkParallelMPI_LIBRARY_DIRS "")
set(vtkParallelMPI_WRAP_HIERARCHY_FILE "${CMAKE_CURRENT_LIST_DIR}/vtkParallelMPIHierarchy.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment