how to use PETSC with C++

Matthew Knepley knepley at mcs.anl.gov
Tue Feb 7 07:57:35 CST 2006


Tomasz Jankowski <tomjan at jay.au.poznan.pl> writes:

       The easiest way to use PETSc from C++ is to reconfigure with
-with-clanguage=C++ and rebuild. You could even put this in a different
arch directory using -PETSC_ARCH=<another name>.

     Thanks,

          Matt

> hello group
>
> I know that no-one like newbie questions, but... unfortunetly I have one
>
> Sorry but I cant find in google or manual the clear example how to use PETSC from C++.
> If there are such, please just point me to them.
>
>
> Initaially I have started with
> ./config/configure.py --download-f-blas-lapack=1
>
> I have sucessfully compiled a few examples and run in parallel mode.
> Now I want to implement PETSC for solwing my linear models.
> I need to switch to C++ because whole code for data manipulation
> (reading,renumbering) and model manipulation (representation, building) I have written in C++.
>
> Maybe it is strange that I'm writing c/c++ code and have such problems but (i'm geneticst not informaticst) compiling
> and linking ,static and shared libs building it is just night mare for me.
>
> So,
>
> I have configured PETSC with such options
> Configure Options: --with-clanguage=C++ --download-f-blas-lapack=1 --with-shared=0 -configModules=PETSc.Configure
>
> and can't compile even such code
> -------------------------------------------
> #include <string>
> #include "petscksp.h"
>
> #undef __FUNCT__
> #define __FUNCT__ "main"
> int main(int argc,char **args)
> {
>    PetscErrorCode ierr;
>    PetscInitialize(argc,args,PETSC_NULL,PETSC_NULL);
>    ierr = PetscFinalize();
>    CHKERRQ(ierr);
>    return 0;
> }
> ----------------------------------------
>
>
> When I try to compile it I obtain this:
>
> mpiCC -c -Wall -g3 -I/home/work/petsc-2.3.0 -I/home/work/petsc-2.3.0/bmake/linux-gnu -I/home/work/petsc-2.3.0/include
> -I/usr/local/include -D__SDIR__="/home/work/blup_pcg" ex4.C
> mpiCC -Wall -g3  -o ex4 ex4.o -Wl,-rpath,/home/work/petsc-2.3.0/lib/linux-gnu -L/home/work/petsc-2.3.0/lib/linux-gnu
> -lpetscksp -lpetscdm -lpetscmat -lpetscvec -lpetsc    -lnsl -lrt
> -Wl,-rpath,/home/work/petsc-2.3.0/externalpackages/fblaslapack/linux-gnu
> -L/home/work/petsc-2.3.0/externalpackages/fblaslapack/linux-gnu-lflapack
> -Wl,-rpath,/home/work/petsc-2.3.0/externalpackages/fblaslapack/linux-gnu
> -L/home/work/petsc-2.3.0/externalpackages/fblaslapack/linux-gnu -lfblas -lm -L/usr/local/lib -llammpio -llamf77mpi -lmpi
> -llam -lutil -ldl -lg2c -lm -L/usr/lib/gcc-lib/i486-linux/3.3.5 -L/usr/lib/gcc-lib/i486-linux/3.3.5/../../.. -lm -lgcc_s
> -lpthread -L/usr/local/lib -L/usr/lib/gcc-lib/i486-linux/3.3.5 -L/usr/lib/gcc-lib/i486-linux/3.3.5/../../.. -llammpio
> -llammpi++ -llamf77mpi -lmpi -llam -lutil -ldl -lstdc++ -lgcc_s -lpthread
> ex4.o(.text+0x2e): In function `main':
> /usr/local/include/mpi2cxx/datatype_inln.h:174: undefined reference to `PetscInitialize(int*, char***, char const*, char
> const*)'
> ex4.o(.text+0x33):/usr/local/include/mpi2cxx/datatype_inln.h:213: undefined reference to `PetscFinalize()'
> collect2: ld returned 1 exit status
> mpiCC: No such file or directory
> make: [ex4] B³±d 1 (zignorowany)
>
>
> ########################################################
> #               tomjan at jay.au.poznan.pl                #
> #              jay.au.poznan.pl/~tomjan/               #
> ########################################################

-- 
"Failure has a thousand explanations. Success doesn't need one" -- Sir Alec Guiness






More information about the petsc-users mailing list