[petsc-users] working with cmake
Zou (Non-US), Ling
ling.zou at inl.gov
Mon Apr 8 17:05:23 CDT 2013
Hi All,
I am trying to use PETSc working with cmake, following the instructions
found on:
================================================================
http://www.mcs.anl.gov/petsc/documentation/faq.html#cmake
Can I use CMake to build my own project that depends on PETSc?Use the
FindPETSc.cmake module from this
repository<https://github.com/jedbrown/cmake-modules/>.
See the CMakeLists.txt from Dohp <https://github.com/jedbrown/dohp> for
example usage.
================================================================
I still have some difficulty to make it work, and I appreciate it if anyone
could give me a hand to resolve the issue.
It is a simple test:
step 1,
I simply copied the file
/opt/packages/petsc/petsc-3.3-p5/src/snes/examples/tutorials/ex3.c to my
working directory /projects/CTest/PETSc/ex3/ex3.c
I know ex3 is working, as when I compile it under
/opt/packages/petsc/petsc-3.3-p5/src/snes/examples/tutorials/ with the
command line
make PETSC_DIR=/opt/packages/petsc/petsc-3.3-p5
PETSC_ARCH=arch-darwin-c-debug ex3
I could run ./ex3 and I could get results like:
===============================================
atol=1e-50, rtol=1e-08, stol=1e-08, maxit=50, maxf=10000
iter = 0,SNES Function norm 5.41468
iter = 1,SNES Function norm 0.295258
iter = 2,SNES Function norm 0.000450229
iter = 3,SNES Function norm 1.38967e-09
Number of SNES iterations = 3
Norm of error 1.49751e-10 Iterations 3
===============================================
step 2,
I copied
FindPETSc.cmake,
FindPackageMultipass.cmake,
ResolveCompilerPaths.cmake,
CorrectWindowsPaths.cmake
from https://github.com/jedbrown/cmake-modules/ to the same working
directory /projects/CTest/PETSc/ex3
step 3,
I copied
CMakeList.txt from
https://github.com/jedbrown/dohp/blob/master/CMakeLists.txt
to
/projects/CTest/PETSc/ex3
then modified it as attached.
step 4,
under /projects/CTest/PETSc/ex3
make clean
rm CMakeCache.txt
PETSC_DIR=/opt/packages/petsc/petsc-3.3-p5 PETSC_ARCH=arch-darwin-c-debug
cmake .
Here is the print out info I got (note there are two fails there but I
ignored them...hmm...maybe I should have not ignored them?):
=========================================
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler:
/opt/packages/openmpi/openmpi-1.6.3/gcc-opt/bin/mpicc
-- Check for working C compiler:
/opt/packages/openmpi/openmpi-1.6.3/gcc-opt/bin/mpicc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Check for working CXX compiler:
/opt/packages/openmpi/openmpi-1.6.3/gcc-opt/bin/mpicxx
-- Check for working CXX compiler:
/opt/packages/openmpi/openmpi-1.6.3/gcc-opt/bin/mpicxx -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- petsc_lib_dir /opt/packages/petsc/petsc-3.3-p5/arch-darwin-c-debug/lib
-- 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.
-- Found PETSc:
/opt/packages/petsc/petsc-3.3-p5/arch-darwin-c-debug/include;/opt/packages/petsc/petsc-3.3-p5/include
-- Performing Test dHAVE_PRAGMA_GCC
-- Performing Test dHAVE_PRAGMA_GCC - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/zoul/projects/CTest/PETSc/ex3
==============================================================
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
"_DMDACreate1d", referenced from:
_main in ex3.c.o
"_DMDAGetCorners", referenced from:
_main in ex3.c.o
_FormFunction in ex3.c.o
_FormJacobian in ex3.c.o
_PostCheck in ex3.c.o
"_DMDAGetInfo", referenced from:
_FormFunction in ex3.c.o
_FormJacobian in ex3.c.o
"_DMDAVecGetArray", referenced from:
_main in ex3.c.o
_FormFunction in ex3.c.o
_FormJacobian in ex3.c.o
_PostCheck in ex3.c.o
"_DMDAVecRestoreArray", referenced from:
_main in ex3.c.o
_FormFunction in ex3.c.o
_FormJacobian in ex3.c.o
_PostCheck in ex3.c.o
"_DMDestroy", referenced from:
_main in ex3.c.o
"_DMGetLocalVector", referenced from:
_FormFunction in ex3.c.o
"_DMGlobalToLocalBegin", referenced from:
_FormFunction in ex3.c.o
"_DMGlobalToLocalEnd", referenced from:
_FormFunction in ex3.c.o
"_DMRestoreLocalVector", referenced from:
_FormFunction in ex3.c.o
"_KSPGetIterationNumber", referenced from:
_PostSetSubKSP in ex3.c.o
"_KSPGetPC", referenced from:
_PostSetSubKSP in ex3.c.o
"_KSPSetTolerances", referenced from:
_PostSetSubKSP in ex3.c.o
"_MatAssemblyBegin", referenced from:
_FormJacobian in ex3.c.o
"_MatAssemblyEnd", referenced from:
_FormJacobian in ex3.c.o
"_MatCreate", referenced from:
_main in ex3.c.o
"_MatDestroy", referenced from:
_main in ex3.c.o
"_MatMPIAIJSetPreallocation", referenced from:
_main in ex3.c.o
"_MatSeqAIJSetPreallocation", referenced from:
_main in ex3.c.o
"_MatSetFromOptions", referenced from:
_main in ex3.c.o
"_MatSetSizes", referenced from:
_main in ex3.c.o
"_MatSetValues", referenced from:
_FormJacobian in ex3.c.o
"_PCBJacobiGetSubKSP", referenced from:
_PostSetSubKSP in ex3.c.o
"_PETSC_COMM_WORLD", referenced from:
_main in ex3.c.o
_Monitor in ex3.c.o
_PostCheck in ex3.c.o
_PostSetSubKSP in ex3.c.o
"_PetscError", referenced from:
_main in ex3.c.o
_FormInitialGuess in ex3.c.o
_FormFunction in ex3.c.o
_FormJacobian in ex3.c.o
_Monitor in ex3.c.o
_PostCheck in ex3.c.o
_PostSetSubKSP in ex3.c.o
...
"_PetscFinalize", referenced from:
_main in ex3.c.o
"_PetscInitialize", referenced from:
_main in ex3.c.o
"_PetscObjectSetName", referenced from:
_main in ex3.c.o
"_PetscOptionsGetInt", referenced from:
_main in ex3.c.o
"_PetscOptionsGetReal", referenced from:
_main in ex3.c.o
"_PetscOptionsHasName", referenced from:
_main in ex3.c.o
"_PetscPrintf", referenced from:
_main in ex3.c.o
_Monitor in ex3.c.o
_PostCheck in ex3.c.o
_PostSetSubKSP in ex3.c.o
"_PetscViewerDestroy", referenced from:
_main in ex3.c.o
"_PetscViewerDrawOpen", referenced from:
_main in ex3.c.o
"_SNESCreate", referenced from:
_main in ex3.c.o
"_SNESDestroy", referenced from:
_main in ex3.c.o
"_SNESGetIterationNumber", referenced from:
_main in ex3.c.o
_PostCheck in ex3.c.o
_PostSetSubKSP in ex3.c.o
"_SNESGetKSP", referenced from:
_PostSetSubKSP in ex3.c.o
"_SNESGetSNESLineSearch", referenced from:
_main in ex3.c.o
"_SNESGetSolution", referenced from:
_Monitor in ex3.c.o
"_SNESGetTolerances", referenced from:
_main in ex3.c.o
"_SNESLineSearchGetPreCheck", referenced from:
_PostCheck in ex3.c.o
"_SNESLineSearchGetSNES", referenced from:
_PostCheck in ex3.c.o
_PostSetSubKSP in ex3.c.o
"_SNESLineSearchSetPostCheck", referenced from:
_main in ex3.c.o
"_SNESLineSearchSetPreCheck", referenced from:
_main in ex3.c.o
"_SNESMonitorSet", referenced from:
_main in ex3.c.o
"_SNESSetFromOptions", referenced from:
_main in ex3.c.o
"_SNESSetFunction", referenced from:
_main in ex3.c.o
"_SNESSetJacobian", referenced from:
_main in ex3.c.o
"_SNESSolve", referenced from:
_main in ex3.c.o
"_VecAXPY", referenced from:
_main in ex3.c.o
"_VecCopy", referenced from:
_PostCheck in ex3.c.o
"_VecDestroy", referenced from:
_main in ex3.c.o
"_VecDuplicate", referenced from:
_main in ex3.c.o
"_VecNorm", referenced from:
_main in ex3.c.o
"_VecSet", referenced from:
_FormInitialGuess in ex3.c.o
"_VecView", referenced from:
_Monitor in ex3.c.o
"_petscstack", referenced from:
_main in ex3.c.o
_FormInitialGuess in ex3.c.o
_FormFunction in ex3.c.o
_FormJacobian in ex3.c.o
_Monitor in ex3.c.o
_PreCheck in ex3.c.o
_PostCheck in ex3.c.o
...
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [MyTest] Error 1
make[1]: *** [CMakeFiles/MyTest.dir/all] Error 2
make: *** [all] Error 2
==========================================
Thank you,
Ling
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130408/c18c6ffb/attachment.html>
-------------- next part --------------
#######################################################################################
# The original CMakeList.txt file is downloaded from:
# https://github.com/jedbrown/dohp/blob/master/CMakeLists.txt
# It was modified for my own project.
#######################################################################################
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)
include (CheckCSourceCompiles) # The name is misleading, this also tries to link
check_c_source_compiles ("
#define PragmaQuote(a) _Pragma(#a)
#define PragmaGCC(a) PragmaQuote(GCC a)
int main(int argc,char *argv[]) {
PragmaGCC(diagnostic ignored \"-Wconversion\")
char c = (int)argv[0][0] + argv[argc-1][0];
return c;
}" dHAVE_PRAGMA_GCC)
# LZ: Adds flags to the compiler command line. I probably don't need it atm.
add_definitions (-std=c99)
# 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)
#add_subdirectory (include)
#add_subdirectory (src)
FILE (GLOB SourceFileList *.C)
ADD_EXECUTABLE (MyTest ${SourceFileList})
More information about the petsc-users
mailing list