I have a pretty beginners' question, but I'm really lost now. I'm beginning with PETSc, but I have problems with compilation of my code. I'm trying to use my own Makefile, but compiler keeps yelling "undefined reference" error. I've tried to figure it out by myself for several hours, but I simply don't see the mistake. So, if you'll recognize the mistake, your help will be greatly appreciated.
This is the whole error message:
mpicc petscLUFact.o -L/home/martin/petsc-3.5.2/arch-linux2-c-debug/lib
petscLUFact.o: In function `main':
/home/martin/Dokumenty/Programovani/petscLUFact.c:18: undefined reference to `PetscInitialize'
/home/martin/Dokumenty/Programovani/petscLUFact.c:20: undefined reference to `PETSC_COMM_WORLD'
/home/martin/Dokumenty/Programovani/petscLUFact.c:20: undefined reference to `MatCreate'
/home/martin/Dokumenty/Programovani/petscLUFact.c:21: undefined reference to `MatSetSizes'
/home/martin/Dokumenty/Programovani/petscLUFact.c:22: undefined reference to `MatSetFromOptions'
/home/martin/Dokumenty/Programovani/petscLUFact.c:23: undefined reference to `MatMPIAIJSetPreallocation'
/home/martin/Dokumenty/Programovani/petscLUFact.c:24: undefined reference to `MatGetOwnershipRange'
/home/martin/Dokumenty/Programovani/petscLUFact.c:26: undefined reference to `MatDestroy'
/home/martin/Dokumenty/Programovani/petscLUFact.c:28: undefined reference to `PetscFinalize'
/home/martin/Dokumenty/Programovani/petscLUFact.c:20: undefined reference to `PetscError'
/home/martin/Dokumenty/Programovani/petscLUFact.c:24: undefined reference to `PetscError'
/home/martin/Dokumenty/Programovani/petscLUFact.c:23: undefined reference to `PetscError'
/home/martin/Dokumenty/Programovani/petscLUFact.c:22: undefined reference to `PetscError'
/home/martin/Dokumenty/Programovani/petscLUFact.c:21: undefined reference to `PetscError'
collect2: error: ld returned 1 exit status
make: *** [petscLUFact] Error 1
And this is my .c file - it's not completed, it's just a test:
static char help[] = "Reads a PETSc matrix and vector from a file and reorders it.\n\
-f0 <input_file> : first file to load (small system)\n\
-f1 <input_file> : second file to load (larger system)\n\n";
#include <petscsys.h>
#include <petscmat.h>
int main( int argc, char **args ) {
Mat A; // matice
//IS isrow,iscol; // permutace radku a sloupcu
PetscInt r = 5, c = 5; // rozmery matice
PetscInt i,j; // souradnice v matici
PetscInt Istart, Iend;
PetscInt Ii; // pocitadlo
PetscScalar v; // 2-rozmerne pole ???
PetscErrorCode ierr;
PetscInitialize( &argc, &args, (char*)0, help );
ierr = MatCreate( PETSC_COMM_WORLD, &A );CHKERRQ( ierr );
ierr = MatSetSizes( A, PETSC_DECIDE, PETSC_DECIDE, r*c, r*c );CHKERRQ(ierr);
ierr = MatSetFromOptions(A);CHKERRQ(ierr);
ierr = MatMPIAIJSetPreallocation( A, 5, PETSC_NULL, 5, PETSC_NULL );CHKERRQ(ierr);
ierr = MatGetOwnershipRange(A,&Istart,&Iend);CHKERRQ(ierr);
MatDestroy(&A);
PetscFinalize();
return 0;
}
Here is my Makefile:
include ${PETSC_DIR}/conf/variables
include ${PETSC_DIR}/conf/rules
CFLAGS=-I${PETSC_DIR}/include -I${PETSC_DIR}/${PETSC_ARCH}/include
petscLUFact: petscLUFact.o
mpicc petscLUFact.o -L${LD_LIBRARY_PATH}
petscLUFact.o: petscLUFact.c
mpicc ${CFLAGS} -c petscLUFact.c -o petscLUFact.o
In $PETSC_DIR/include
and ${PETSC_DIR}/${PETSC_ARCH}/include
there are petsc header (.h) files located.
Values of my system variables are:
$PETSC_DIR=/home/martin/petsc-3.5.2
$PETSC_ARCH=arch-linux2-c-debug
$LD_LIBRARY_PATH=/home/martin/petsc-3.5.2/arch-linux2-c-debug/lib
And this is the structure of my LD_LIBRARY_PATH folder:
arch-linux2-c-debug/lib
├── libpetsc.a
├── libpetsc.so -> libpetsc.so.3.5.2
├── libpetsc.so.3.5 -> libpetsc.so.3.5.2
├── libpetsc.so.3.5.2
├── modules
│ └── 3.5.2-arch-linux2-c-debug
└── pkgconfig
└── PETSc.pc