[petsc-users] funny link error

Scott Kruger kruger at txcorp.com
Mon Mar 22 11:16:39 CDT 2021


The short answer is $PETSC_INSTALL_DIR/lib/pkgconfig/PETSc.pc

Attached is a PETSc CMake snippet that should show you how to use
pkg-config.

It also shows how to set the compilers to the same as PETSc's for build
consistency, but this part is not strictly necessary (but perhaps a good
idea).

FYI, Barry has been pushing to get a CMake build example as part of the
test harness with the help of Jed and myself, but the Windows issues
have been a real hold-up.

Scott


On 2021-03-22 11:03, Mark Adams did write:
> Thanks Scott,
> 
> Can you please tell us where this pkg-config file is?
> 
> Thank again,
> Mark
> 
> On Mon, Mar 22, 2021 at 10:45 AM Scott Kruger <kruger at txcorp.com> wrote:
> 
> >
> > From you make.log, it looks like petsc found it  here:
> > /opt/cray/wlm_detect/1.3.3-7.0.1.1_4.19__g7109084.ari/lib64
> >
> > PETSc has it and found it because BuildSystem did the query of what
> > it takes to get C/C++/Fortran to work together.  Why is it needed?
> > That's up to Cray.
> >
> > But the question is:
> >
> > How is your CMake build getting PETSc info?
> >
> > If
> > a) it using pkg-config and CMake's ability to parse it, then it looks like
> > our pkg-config export might need work.
> > We'd need to see the pkg-config file to be sure though.
> >
> > and if
> > b) it is not using pkg-config, then the answer is it should.
> >
> > Scott
> >
> >
> > On 2021-03-21 08:25, Mark Adams did write:
> > > We are having problems with linking and use static linking.
> > > We get this error and have seen others like it (eg, lpetsc_lib_gcc_s)
> > >
> > > /usr/bin/ld: cannot find -lpetsc_lib_wlm_detect-NOTFOUND
> > >
> > > wlm_detect is some sort of system library, but I have no idea where this
> > > petsc string comes from.
> > > This is on Cori and the application uses cmake.
> > > I can run PETSc tests fine.
> > >
> > > Any ideas?
> > >
> > > Thanks,
> > > Mark
> >
> >
> >
> >
> > --
> > Scott Kruger
> > Tech-X Corporation               kruger at txcorp.com
> > 5621 Arapahoe Ave, Suite A       Phone: (720) 466-3196
> > Boulder, CO 80303                Fax:   (303) 448-7756
> >

-- 
Scott Kruger
Tech-X Corporation               kruger at txcorp.com
5621 Arapahoe Ave, Suite A       Phone: (720) 466-3196
Boulder, CO 80303                Fax:   (303) 448-7756
-------------- next part --------------
# set root of location to find PETSc configuration
set(PETSC $ENV{PETSC_DIR}/$ENV{PETSC_ARCH})
set(ENV{PKG_CONFIG_PATH} ${PETSC}/lib/pkgconfig)

# Determine PETSc compilers
execute_process ( COMMAND pkg-config PETSc --variable=ccompiler COMMAND tr -d '\n' OUTPUT_VARIABLE C_COMPILER)
SET(CMAKE_C_COMPILER ${C_COMPILER})
  execute_process ( COMMAND pkg-config PETSc --variable=cxxcompiler COMMAND tr -d '\n' OUTPUT_VARIABLE CXX_COMPILER)
if (CXX_COMPILER)
  SET(CMAKE_CXX_COMPILER ${CXX_COMPILER})
endif (CXX_COMPILER)
execute_process ( COMMAND pkg-config PETSc --variable=fcompiler COMMAND tr -d '\n' OUTPUT_VARIABLE FORTRAN_COMPILER)
if (FORTRAN_COMPILER)
  SET(CMAKE_Fortran_COMPILER ${FORTRAN_COMPILER})
  enable_language(Fortran)
endif (FORTRAN_COMPILER)


# Get petsc and it's dependencies
find_package(PkgConfig REQUIRED)
pkg_search_module(PETSC REQUIRED IMPORTED_TARGET PETSc)
target_link_libraries(ex1 PkgConfig::PETSC)


More information about the petsc-users mailing list