[petsc-users] working with cmake

Jed Brown jedbrown at mcs.anl.gov
Mon Apr 8 17:17:53 CDT 2013


"Zou (Non-US), Ling" <ling.zou at inl.gov> writes:

> -- Recognized PETSc install with single library for all packages
> -- Performing Test MULTIPASS_TEST_1_petsc_works_minimal
> -- Performing Test MULTIPASS_TEST_1_petsc_works_minimal - Failed
> -- Performing Test MULTIPASS_TEST_2_petsc_works_allincludes
> -- Performing Test MULTIPASS_TEST_2_petsc_works_allincludes - Failed
> -- Performing Test MULTIPASS_TEST_3_petsc_works_alllibraries
> -- Performing Test MULTIPASS_TEST_3_petsc_works_alllibraries - Success
> -- PETSc only need minimal includes, but requires explicit linking to all
> dependencies.  This is expected when PETSc is built with static libraries.

This is okay, and we can do no better if you built with static libraries.

> step 5
> make
> However I got the error messages:
> ==========================================
> Scanning dependencies of target MyTest
> [100%] Building C object CMakeFiles/MyTest.dir/ex3.c.o
> Linking C executable MyTest
> Undefined symbols for architecture x86_64:
>   "_DMCreateGlobalVector", referenced from:
>       _main in ex3.c.o

Your CMakeLists.txt does not actually link any libraries. Try the file
below:



cmake_minimum_required (VERSION 2.8)
project (MyTest)

list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR})

# Normally PETSc is built with MPI, if not, use CC=mpicc, etc
find_package (PETSc REQUIRED)

# Essential: include our directories first otherwise we can get internal headers from some installed path
include_directories (${PETSC_INCLUDES})
add_definitions (${PETSC_DEFINITIONS})

set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

FILE (GLOB SourceFileList *.C)
ADD_EXECUTABLE (MyTest ${SourceFileList})
TARGET_LINK_LIBRARIES(MyTest ${PETSC_LIBRARIES})   # <---- new line


More information about the petsc-users mailing list