[petsc-users] compile error of CHKERRQ when linking to PETSC

Satish Balay balay at mcs.anl.gov
Wed Mar 3 12:25:02 CST 2021


CHKERRQ() returns error code from the routine. However if the routine is set to return void - use CHKERRABORT()

CHKERRABORT(PETSC_COMM_WORLD,ierr)

Satish

On Wed, 3 Mar 2021, feng wang wrote:

> Dear All,
> 
> I am new to PETSC and have exercised on a few simple programs to get myself familiar with PETSC and the simple codes work properly. So the environment for PETSC is set up with no problem. Now I am trying to do some work in my big code which is written in C++.  Somehow, I get the compile error for  "CHKERRQ", and the error message is:
> 
> ~/cfd/petsc/include/petscerror.h:464:196: error: return-statement with a value, in function returning 'void' [-fpermissive]
>        do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");} while (0)
>                                                                                                                                                                            ^
> domain/cfd/petsc_nk.cpp:23:7: note: in expansion of macro ‘CHKERRQ’
>        CHKERRQ(ierr);
> 
> Basically, it complains about "CHKERRQ", if I remove "CHKERRQ", the code compiles with no problem. Could someone please shine some light on this?
> 
> Many thanks,
> Feng
> 


More information about the petsc-users mailing list