link error

Yixun Liu enjoywm at cs.wm.edu
Sat Feb 14 16:55:41 CST 2009


Satish Balay wrote:
> Don't know cmake.
>
> You'll have to make sure 'all' compiler options used to compile the
> PETSc example are also used in your build system. If you miss
> something - you'll have to go back - and add it in.
>
> So:
>
> - look at the make output of compiling a PETSc example
> - look at the make output from compiling your code.
> - look for whats missing - and add it to your cmake stuff..
>
> [most likely you are missing "-lX11" at link time.]
>
> Satish
>
> On Wed, 11 Feb 2009, Yixun Liu wrote:
>
>   
>>  I can successfully compile the example with PETSC
>> makefile. However, I need integrate PETSC into an existing
>> application, which use CMake to generate makefile. I add the
>> following into CMakelist.txt and use CMake to generate makefile and
>> then make.
>>     
>
>   
>> #----------
>> # PETSc
>> #----------
>> SET(PETSC_DIR /home/scratch/yixun/petsc-3.0.0-p3)
>> SET(PETSC_ARCH /linux-gnu-c-debug)
>> SET(X11_DIR /usr/X11R6)
>> SET(PETSC_INCLUDE_DIR ${PETSC_DIR}/include
>> ${PETSC_DIR}/${PETSC_ARCH}/include)
>> SET(PETSC_LIB_DIR ${PETSC_DIR}/${PETSC_ARCH}/lib ${X11_DIR}/lib64
>> ${X11_DIR}/lib/X11)
>>     
When I add the following in my application, there are many link errors.
Vec x,b,u;
Mat K;
KSP ksp;
PetscMPIInt size, rank;
MPI_Comm_size(PETSC_COMM_WORLD,&size);
MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
VecCreate(PETSC_COMM_WORLD,&u)


Errors:
/home/scratch/yixun/petsc-3.0.0-p3/linux-gnu-c-debug/lib/libpetscvec.a(dlregisvec.o):
In function `VecInitializePackage':
/home/scratch/yixun/petsc-3.0.0-p3/src/vec/vec/interface/dlregisvec.c:183:
undefined reference to `PetscObjectComposedDataRegister'
/home/scratch/yixun/petsc-3.0.0-p3/linux-gnu-c-debug/lib/libpetscvec.a(pmap.o):
In function `PetscMapSetUp':
/home/scratch/yixun/petsc-3.0.0-p3/src/vec/vec/impls/mpi/pmap.c:136:
undefined reference to `PetscSplitOwnership'
/home/scratch/yixun/petsc-3.0.0-p3/linux-gnu-c-debug/lib/libpetscvec.a(index.o):
In function `ISSetPermutation':
/home/scratch/yixun/petsc-3.0.0-p3/src/vec/is/interface/index.c:140:
undefined reference to `PetscSortInt'
/home/scratch/yixun/petsc-3.0.0-p3/linux-gnu-c-debug/lib/libpetscvec.a(isltog.o):
In function `ISLocalToGlobalMappingGetInfo':
/home/scratch/yixun/petsc-3.0.0-p3/src/vec/is/utils/isltog.c:864:
undefined reference to `PetscSortIntWithArray'
...



I can make ex2 using command make ex2. The link command is like following,

mpicc -Wall -Wwrite-strings -Wno-strict-aliasing -g3 -o ex2 ex2.o
-Wl,-rpath,/home/scratch/yixun/petsc-3.0.0-p3/linux-gnu-c-debug/lib
-L/home/scratch/yixun/petsc-3.0.0-p3/linux-gnu-c-debug/lib -lpetscksp
-lpetscdm -lpetscmat -lpetscvec -lpetsc -lX11 -llapack -lblas -lm
-L/usr/lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1 -L/lib64
-L/usr/x86_64-suse-linux/lib -ldl -llammpio -llamf77mpi -lmpi -llam
-lutil -lgcc_s -lpthread -lgfortranbegin -lgfortran -lm -lm -ldl
-llammpio -llamf77mpi -lmpi -llam -lutil -lgcc_s -lpthread -ldl


The command I use to link my application is like,

/usr/bin/mpiCC -DWITHOUT_MTL -D_YAV_ -D_LINUX_ -ansi -Wall -fsigned-char
-fsigned-bitfields -Wno-deprecated -ftemplate-depth-50 -Wall -fPIC
CMakeFiles/PETScSolver.dir/PETScSolver.o
CMakeFiles/PETScSolver.dir/PETScRegistrationMesh.o
CMakeFiles/PETScSolver.dir/BlockList.o
CMakeFiles/PETScSolver.dir/Point.o -o ../../../bin/PETScSolver -rdynamic
-L/home/scratch/yixun/Biofemir/trunk/build/lib
-L/home/scratch/yixun/VTK-mpicc/Build/bin
-L/home/scratch/yixun/ITK-mpicc/Build/bin -L/lib/LINUX
-L/home/scratch/yixun/petsc-3.0.0-p3/linux-gnu-c-debug/lib
-L/usr/X11R6/lib64 -L/usr/X11R6/lib/X11
../../../lib/libTetrahedrisationNG.a ../../../lib/libTetraImageNG.a
../../../lib/libImageDataNG.a -lITKCommon -lITKIO -lvtkIO -lpetsc
-lpetscksp -lpetscmat -lpetscvec -lpetsccontrib -lpetscdm -lpetscsnes
-lpetscts -lX11 -llapack -lblas -llam -lutil -lm -llammpio -lmpi -lgcc_s
-lpthread -lgfortranbegin -ldl ../../../lib/libTetrahedrisationNG.a
../../../lib/libGraphics2DNG.a ../../../lib/libGraphics3DNG.a
../../../lib/libInrimageNG.a ../../../lib/libBasics.a
../../../lib/libmipsZ.a -lITKNrrdIO -litkgdcm -litkjpeg12 -litkjpeg16
-litkopenjpeg -luuid -litkpng -litktiff -litkjpeg8 -lITKSpatialObject
-lITKCommon -litkvnl_inst -litkvnl_algo -litkvnl -litkv3p_netlib
-litkvcl -lITKMetaIO -litksys -lITKDICOMParser -lITKEXPAT -lITKniftiio
-lITKznz -litkzlib -lvtkFiltering -lvtkCommon -lpthread -lm
-lvtkDICOMParser -lvtkNetCDF -lvtkmetaio -lvtksqlite -lvtkpng -lvtktiff
-lvtkzlib -lvtkjpeg -lvtkexpat -lvtksys -lm -ldl
-Wl,-rpath,/home/scratch/yixun/Biofemir/trunk/build/lib:/home/scratch/yixun/VTK-mpicc/Build/bin:/home/scratch/yixun/ITK-mpicc/Build/bin:/lib/LINUX:/home/scratch/yixun/petsc-3.0.0-p3/linux-gnu-c-debug/lib:/usr/X11R6/lib64:/usr/X11R6/lib/X11



I cannot see the difference, but why it doesn't work?

Thanks.
Yixun






More information about the petsc-users mailing list