首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PETSc未定义引用

PETSc未定义引用
EN

Stack Overflow用户
提问于 2014-10-21 11:32:36
回答 1查看 2.6K关注 0票数 1

我有一个相当初级的问题,但我现在真的迷路了。我从PETSc开始,但是我的代码编译有问题。我正在尝试使用我自己的Makefile,但是编译器总是大喊“未定义的引用”错误。几个小时以来,我一直在努力想办法解决这个问题,但我根本没有看到这个错误。因此,如果你认识到这个错误,你的帮助将会受到极大的感谢。

这是整个错误消息:

代码语言:javascript
复制
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

这是我的.c文件-它还没有完成,它只是一个测试:

代码语言:javascript
复制
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;
}

这是我的Makefile:

代码语言:javascript
复制
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

$PETSC_DIR/include${PETSC_DIR}/${PETSC_ARCH}/include中,有位于petsc头(.h)文件。

我的系统变量的值是:

代码语言:javascript
复制
$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

这是我的LD_LIBRARY_PATH文件夹的结构:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-25 14:44:03

(注释和编辑中的答案。见Question with no answers, but issue solved in the comments (or extended in chat))

@Wesley Bland写道:

您实际上在哪里将库传递给链接器(或者在本例中是mpicc命令)?看起来,除了您的-lpetsc标志之外,您还需要一个-L<stuff>

“任择议定书”写道:

我向-lpetsc添加了一个Makefile标志,现在看起来如下所示:

代码语言:javascript
复制
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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26485666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档