Friday, 15 July 2011

c - PETSc undefined reference -



c - PETSc undefined reference -

i have pretty beginners' question, i'm lost now. i'm origin petsc, have problems compilation of code. i'm trying utilize own makefile, compiler keeps yelling "undefined reference" error. i've tried figure out myself several hours, don't see mistake. so, if you'll recognize mistake, help appreciated.

this 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 `petscinitialize' /home/martin/dokumenty/programovani/petsclufact.c:20: undefined reference `petsc_comm_world' /home/martin/dokumenty/programovani/petsclufact.c:20: undefined reference `matcreate' /home/martin/dokumenty/programovani/petsclufact.c:21: undefined reference `matsetsizes' /home/martin/dokumenty/programovani/petsclufact.c:22: undefined reference `matsetfromoptions' /home/martin/dokumenty/programovani/petsclufact.c:23: undefined reference `matmpiaijsetpreallocation' /home/martin/dokumenty/programovani/petsclufact.c:24: undefined reference `matgetownershiprange' /home/martin/dokumenty/programovani/petsclufact.c:26: undefined reference `matdestroy' /home/martin/dokumenty/programovani/petsclufact.c:28: undefined reference `petscfinalize' /home/martin/dokumenty/programovani/petsclufact.c:20: undefined reference `petscerror' /home/martin/dokumenty/programovani/petsclufact.c:24: undefined reference `petscerror' /home/martin/dokumenty/programovani/petsclufact.c:23: undefined reference `petscerror' /home/martin/dokumenty/programovani/petsclufact.c:22: undefined reference `petscerror' /home/martin/dokumenty/programovani/petsclufact.c:21: undefined reference `petscerror' collect2: error: ld returned 1 exit status make: *** [petsclufact] error 1

and .c file - it's not completed, it's test:

static char help[] = "reads petsc matrix , vector file , reorders it.\n\ -f0 <input_file> : first file load (small system)\n\ -f1 <input_file> : sec file 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 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(); homecoming 0; }

here 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 , ${petsc_dir}/${petsc_arch}/include there petsc header (.h) files located.

values of scheme 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 construction of ld_library_path folder:

class="lang-none prettyprint-override">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

(answers in comments , edit. see question no answers, issue solved in comments)

@wesley bland wrote:

where passing library linker (or in case mpicc command? looks need -lpetsc in there in add-on -l<stuff> flag.

the op wrote:

i added -lpetsc flag makefile, looks now:

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 -o petsclufact -l${ld_library_path} -lpetsc petsclufact.o: petsclufact.c mpicc ${cflags} -c petsclufact.c -o petsclufact.o

c makefile mpi petsc

No comments:

Post a Comment