[petsc-users] cmake, pkg-config and Libs.private
Yann Jobic
yann.jobic at univ-amu.fr
Wed Mar 11 05:59:48 CDT 2020
Hi all,
I'm trying to create a correct CMakeLists.txt in order to compile a
petsc program.
I can compile my code, but i cannot link it.
I have this link command :
/local/lib/openmpi/gcc8/4.0.3/bin/mpicc -g -rdynamic
CMakeFiles/Test1.dir/src/dvm_dg1D_qff_2dV.c.o
CMakeFiles/Test1.dir/src/computeHermCoeff.c.o
CMakeFiles/Test1.dir/src/dg1DFuncs.c.o -o Test1
-L/local/lib/petsc/3.12/p4/gcc_8.3.1/openmpi-gcc-opti/lib -lpetscts
-lpetscsnes -lpetscksp -lpetscdm -lpetscmat -lpetscvec -lpetscsys
/bin/ld:
/local/lib/petsc/3.12/p4/gcc_8.3.1/openmpi-gcc-opti/lib/libpetscsys.a(dlimpl.o):
référence au symbole non défini « dlclose@@GLIBC_2.2.5 »
//usr/lib64/libdl.so.2 : erreur lors de l'ajout de symboles : DSO
manquant dans la ligne de commande
But if i add Libs.private to this line in a terminal to test the
command, it works:
mpicc -rdynamic CMakeFiles/Test1.dir/src/dvm_dg1D_qff_2dV.c.o
CMakeFiles/Test1.dir/src/computeHermCoeff.c.o
CMakeFiles/Test1.dir/src/dg1DFuncs.c.o -o Test1
-L/local/lib/petsc/3.12/p4/gcc_8.3.1/openmpi-gcc-opti/lib -lpetscts
-lpetscsnes -lpetscksp -lpetscdm -lpetscmat -lpetscvec -lpetscsys
-L/local/lib/petsc/3.12/p4/gcc_8.3.1/openmpi-gcc-opti/lib
-L/local/lib/openmpi/gcc8/4.0.3/lib -L/usr/lib/gcc/x86_64-redhat-linux/8
-lHYPRE -lcmumps -ldmumps -lsmumps -lzmumps -lmumps_common -lpord
-lscalapack -lumfpack -lklu -lcholmod -lbtf -lccolamd -lcolamd -lcamd
-lamd -lsuitesparseconfig -lsuperlu -lsuperlu_dist -lml -lp4est -lsc
-lflapack -lfblas -lptesmumps -lptscotchparmetis -lptscotch
-lptscotcherr -lesmumps -lscotch -lscotcherr -lnetcdf -lhdf5hl_fortran
-lhdf5_fortran -lhdf5_hl -lhdf5 -lparmetis -lmetis -ltriangle -lm -lz
-lsz -lX11 -lstdc++ -ldl -lmpi_usempif08 -lmpi_usempi_ignore_tkr
-lmpi_mpifh -lmpi -lgfortran -lm -lgfortran -lm -lgcc_s -lquadmath
-lpthread -lrt -lquadmath -lstdc++ -ldl
So I should be using Libs.private in the link command, but i don't know
how to tell cmake to do so.
What is the correct line that i have to add to CMakeLists.txt in order
to have Libs and Libs.private from the PETSc.pc file ?
What I am doing wrong ?
Thanks,
Best regards,
Yann
PS : My CMakeLists.txt so far :
cmake_minimum_required(VERSION 2.8.11)
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# 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)
find_package(PkgConfig REQUIRED)
pkg_search_module(PETSC REQUIRED PETSc)
set(SOURCES src/dvm_dg1D_qff_2dV.c src/computeHermCoeff.c src/dg1DFuncs.c)
include_directories(${PETSC_INCLUDE_DIRS})
include_directories(includes)
add_executable(Test1 ${SOURCES})
target_link_libraries(Test1 ${PETSC_LDFLAGS})
More information about the petsc-users
mailing list