[petsc-users] Configuring with CMake

Palmer, Bruce J Bruce.Palmer at pnnl.gov
Fri Mar 25 10:26:45 CDT 2022


I didn't get around to writing a reproducer, but I did send an extensive complaint to the CMake user group. I haven't heard anything back yet. I finally got this to work by adding this to the CMakeLists.txt file

if (NOT BUILD_SHARED_LIBS)
  target_link_libraries(gridpack_math 
    PUBLIC
    ${PETSC_STATIC_LIBRARIES}
  )
  target_link_options(gridpack_math PUBLIC ${PETSC_STATIC_LDFLAGS})
endif()

I had to add PETSC_STATIC_LIBRARIES and PETSC_STATIC_LDFLAGS to get everything to compile.

Bruce

On 2/22/22, 1:10 PM, "Jed Brown" <jed at jedbrown.org> wrote:

    Check twice before you click! This email originated from outside PNNL.


    It would be good to report a reduced test case upstream. They may not fix it, but a lot of things related to static libraries don't work without coaxing and they'll never get fixed if people who use CMake with static libraries don't make their voices heard.

    "Palmer, Bruce J via petsc-users" <petsc-users at mcs.anl.gov> writes:

    > Argh, I'm an idiot. I can't write a proper print statement in CMake.
    >
    > The PETSC_STATIC_LDFLAGS variable is showing all the libraries so probably all I need to do is substitute that for PETSC_LDFLAGS in the GridPACK CMake build (once I find it) when the build is static.
    >
    > On 2/22/22, 10:39 AM, "Satish Balay" <balay at mcs.anl.gov> wrote:
    >
    >     You can run 'pkg-config --static --libs PETSC_DIR/PETSC_ARCH/lib/pkgconfig/petsc.pc' to verify if pkg-config is able to obtain 'Libs.private' values.
    >
    >     And then you would need help from someone who can debug cmake - on why PETSC_STATIC set by cmake does not reflect this value [as it should - per the FindPkgConfig doc]
    >
    >     [sorry - I don't understand cmake - or how one would debug cmake issues]
    >
    >     Satish
    >
    >     On Tue, 22 Feb 2022, Palmer, Bruce J via petsc-users wrote:
    >
    >     > The static versions of the variables exist (PETSC_STATIC), but they appear to have the same values as the non-static variables.
    >     >
    >     > As I mentioned, I'm a complete novice at pkgconfig, but it looks like if you could add the contents of Libs.private to the link line, you'd be in business. Any idea how to access this information from CMake?
    >     >
    >     > Bruce
    >     >
    >     > On 2/22/22, 10:22 AM, "Satish Balay" <balay at mcs.anl.gov> wrote:
    >     >
    >     >     https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcmake.org%2Fcmake%2Fhelp%2Flatest%2Fmodule%2FFindPkgConfig.html&data=04%7C01%7CBruce.Palmer%40pnnl.gov%7C65eb4c4214a04fae212408d9f647ca0b%7Cd6faa5f90ae240338c0130048a38deeb%7C0%7C0%7C637811610469013883%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=PRqeyGFzP%2B4nJr7ugFirs4wUmB0PR6fstQJ31cPzdPM%3D&reserved=0
    >     >
    >     >     >>>
    >     >     Two sets of values exist: One for the common case (<XXX> = <prefix>) and another for the information pkg-config provides when called with the --static option (<XXX> = <prefix>_STATIC).
    >     >     <<<
    >     >
    >     >     So perhaps CMAKE is already setting the _STATIC variant of (for PETSC_LIB or equivalent) variable that's currently used)?
    >     >
    >     >     Satish
    >     >
    >     >     On Tue, 22 Feb 2022, Palmer, Bruce J via petsc-users wrote:
    >     >
    >     >     > The contents of the petsc.pc file are listed below. It looks good to me. The Libs.private variable seems to include the -lf2clapack and -lf2cblas libraries. I don't know how this info gets propagated up the build chain.
    >     >     >
    >     >     > Bruce
    >     >     >
    >     >     > prefix=/pic/projects/gridpack/software/petsc-3.16.3/linux-openmpi-gnu-cxx-complex-opt
    >     >     > exec_prefix=${prefix}
    >     >     > includedir=${prefix}/include
    >     >     > libdir=${prefix}/lib
    >     >     > ccompiler=mpicc
    >     >     > cflags_extra=-fPIC -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -fstack-protector -fvisibility=hidden -g -O
    >     >     > cflags_dep=-MMD -MP
    >     >     > ldflag_rpath=-Wl,-rpath,
    >     >     > cxxcompiler=mpicxx
    >     >     > cxxflags_extra=-Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -fstack-protector -fvisibility=hidden -g -O  -std=gnu++11
    >     >     > fcompiler=mpif90
    >     >     > fflags_extra=-Wall -ffree-line-length-0 -Wno-unused-dummy-argument -g -O
    >     >     >
    >     >     > Name: PETSc
    >     >     > Description: Library to solve ODEs and algebraic equations
    >     >     > Version: 3.16.3
    >     >     > Cflags:   -I${includedir} -I/pic/projects/gridpack/software/petsc-3.16.3/include
    >     >     > Libs: -L${libdir} -lpetsc
    >     >     > Libs.private: -L/pic/projects/gridpack/software/petsc-3.16.3/linux-openmpi-gnu-cxx-complex-opt/lib -L/share/apps/openmpi/3.0.1/gcc/6.1.0/lib -L/qfs/projects/ops/rh6/gcc/6.1.0/lib/gcc/x86_64-pc-linux-gnu/6.1.0 -L/qfs/projects/ops/rh6/gcc/6.1.0/lib/gcc -L/qfs/projects/ops/rh6/gcc/6.1.0/lib64 -L/qfs/projects/ops/rh6/gcc/6.1.0/lib -lspqr -lumfpack -lklu -lcholmod -lbtf -lccolamd -lcolamd -lcamd -lamd -lsuitesparseconfig -lrt -lsuperlu -lsuperlu_dist -lf2clapack -lf2cblas -lparmetis -lmetis -lm -lstdc++ -ldl -lmpi_usempif08 -lmpi_usempi_ignore_tkr -lmpi_mpifh -lmpi -lgfortran -lm -lgfortran -lm -lgcc_s -lquadmath -lpthread -lquadmath -lstdc++ -ldl
    >     >     >
    >     >     > On 2/22/22, 8:39 AM, "Satish Balay" <balay at mcs.anl.gov> wrote:
    >     >     >
    >     >     >     The relevant pkg-config commands are:
    >     >     >
    >     >     >     balay at sb /home/balay/petsc (release=)
    >     >     >     $ pkg-config --libs arch-linux-c-debug/lib/pkgconfig/petsc.pc
    >     >     >     -L/home/balay/petsc/arch-linux-c-debug/lib -lpetsc
    >     >     >     balay at sb /home/balay/petsc (release=)
    >     >     >     $ pkg-config --shared --libs arch-linux-c-debug/lib/pkgconfig/petsc.pc
    >     >     >     -L/home/balay/petsc/arch-linux-c-debug/lib -lpetsc
    >     >     >     balay at sb /home/balay/petsc (release=)
    >     >     >     $ pkg-config --static --libs arch-linux-c-debug/lib/pkgconfig/petsc.pc
    >     >     >     -L/home/balay/petsc/arch-linux-c-debug/lib -lpetsc -L/home/balay/soft/mpich-3.4.2/lib -L/usr/lib/gcc/x86_64-redhat-linux/11 -llapack -lblas -lm -lX11 -lstdc++ -ldl -lmpifort -lmpi -lgfortran -lm -lgfortran -lm -lgcc_s -lquadmath -lstdc++ -ldl
    >     >     >
    >     >     >
    >     >     >     And more example usages in share/petsc/Makefile.user
    >     >     >
    >     >     >     Satish
    >     >     >
    >     >     >
    >     >     >     On Tue, 22 Feb 2022, Barry Smith wrote:
    >     >     >
    >     >     >     >  Bruce,
    >     >     >     >
    >     >     >     >   Can you please send the PkgConfig calls that you make to get the PETSc values? And then exactly what PETSc PkgConfig returns.
    >     >     >     >
    >     >     >     > Thanks
    >     >     >     >
    >     >     >     >    Barry
    >     >     >     >
    >     >     >     >
    >     >     >     > > On Feb 22, 2022, at 11:03 AM, Palmer, Bruce J via petsc-users <petsc-users at mcs.anl.gov> wrote:
    >     >     >     > >
    >     >     >     > > Hi,
    >     >     >     > >
    >     >     >     > > We recently switched the CMake configuration on our GridPACK application to use the PkgConfig utility instead of Jeb Brown’s FindPETSc.cmake module. This seems to work on a number of platforms but it is failing to link on others. It appears that the build cannot find the LAPACK and BLAS libraries. The PETSc library I’m linking to (v3.16.3) was configured with -download-f2cblaslapack so it should have these libraries, but when I try and link one of the test applications in GridPACK I get the errors
    >     >     >     > >
    >     >     >     > > /share/apps/gcc/6.1.0/bin/g++ -pthread -g -rdynamic CMakeFiles/greetings.dir/test/greetings.cpp.o -o greetings  -Wl,-rpath,/qfs/projects/ops/rh6/openmpi/3.0.1/gcc/6.1.0/lib ../math/libgridpack_math.a libgridpack_parallel.a ../timer/libgridpack_timer.a ../environment/libgridpack_environment.a ../math/libgridpack_math.a /pic/projects/gridpack/software/boost_1_65_0/lib/libboost_mpi.a /pic/projects/gridpack/software/boost_1_65_0/lib/libboost_serialization.a /pic/projects/gridpack/software/boost_1_65_0/lib/libboost_random.a /pic/projects/gridpack/software/boost_1_65_0/lib/libboost_filesystem.a /pic/projects/gridpack/software/boost_1_65_0/lib/libboost_system.a /pic/projects/gridpack/software/ga-5.7/build_pr/lib/libga++.a /pic/projects/gridpack/software/ga-5.7/build_pr/lib/libga.a /pic/projects/gridpack/software/ga-5.7/build_pr/lib/libarmci.a -lrt /usr/lib64/librt.so /usr/lib64/libdl.so /qfs/projects/ops/rh6/openmpi/3.0.1/gcc/6.1.0/lib/libmpi.so ../timer/libgridpack_timer.a
    >      libgri
    >     >      dpack_
    >     >     >      parallel.a ../configuration/libgridpack_configuration.a /pic/projects/gridpack/software/petsc-3.16.3/linux-openmpi-gnu-cxx-complex-opt/lib/libpetsc.a
    >     >     >     > > /pic/projects/gridpack/software/petsc-3.16.3/linux-openmpi-gnu-cxx-complex-opt/lib/libpetsc.a(zstart.o): In function `petscinitializef_':
    >     >     >     > > /pic/projects/gridpack/software/petsc-3.16.3/src/sys/objects/ftn-custom/zstart.c:280: undefined reference to `mpi_init_'
    >     >     >     > > /pic/projects/gridpack/software/petsc-3.16.3/linux-openmpi-gnu-cxx-complex-opt/lib/libpetsc.a(baijfact.o): In function `MatSolve_SeqBAIJ_N':
    >     >     >     > > /pic/projects/gridpack/software/petsc-3.16.3/src/mat/impls/baij/seq/baijfact.c:1462: undefined reference to `zgemv_'
    >     >     >     > > /pic/projects/gridpack/software/petsc-3.16.3/src/mat/impls/baij/seq/baijfact.c:1475: undefined reference to `zgemv_'
    >     >     >     > > /pic/projects/gridpack/software/petsc-3.16.3/src/mat/impls/baij/seq/baijfact.c:1478: undefined reference to `zgemv_'
    >     >     >     > > /pic/projects/gridpack/software/petsc-3.16.3/linux-openmpi-gnu-cxx-complex-opt/lib/libpetsc.a(baijfact.o): In function `MatSolve_SeqBAIJ_N_NaturalOrdering':
    >     >     >     > > /pic/projects/gridpack/software/petsc-3.16.3/src/mat/impls/baij/seq/baijfact.c:1407: undefined reference to `zgemv_'
    >     >     >     > > /pic/projects/gridpack/software/petsc-3.16.3/src/mat/impls/baij/seq/baijfact.c:1420: undefined reference to `zgemv_'
    >     >     >     > > /pic/projects/gridpack/software/petsc-3.16.3/linux-openmpi-gnu-cxx-complex-opt/lib/libpetsc.a(baijfact.o):/pic/projects/gridpack/software/petsc-3.16.3/sr
    >     >     >     > >
    >     >     >     > > I suspect that the reason it worked for others and not for me is that they had viable blas and lapack libraries in their path and I don’t. Is there anything special you need to do to make sure that the build is pointed at the libraries that get created with the -download-f2cblaslapack option?
    >     >     >     > >
    >     >     >     > > Bruce Palmer
    >     >     >     >
    >     >     >     >
    >     >     >
    >     >     >
    >     >
    >     >



More information about the petsc-users mailing list