[petsc-users] CMake error in PETSc

Yingjie Wu yjwu16 at gmail.com
Thu Dec 5 07:25:12 CST 2019


Hi,

I installed the latest version of petsc, and compiled the example using
cmke as described above. Compilation can be done, but there is a new
problem while the program is running, as if the program could not find the
shared library libpetsc.so.3.12. How can I solve this problem? The details
are as follows:

lerui at yu1994-ThinkPad-W520:~/tem$ cat CMakeLists.txt
#This is a CMake makefile.
cmake_minimum_required(VERSION 2.8.11)

project(example01cmke)

add_executable(example01cmke ex1.cpp)

find_package(PkgConfig REQUIRED)

set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

pkg_search_module(PETSC REQUIRED PETSc)

message("pkg include dirs: ${PETSC_INCLUDE_DIRS}")

message("pkg include libs: ${PETSC_LIBRARIES}")

message("pkg ldflags: ${PETSC_LDFLAGS}")

include_directories(${PETSC_INCLUDE_DIRS})

target_link_libraries(example01cmke ${PETSC_LDFLAGS})

lerui at yu1994-ThinkPad-W520:~/tem$ mkdir build
lerui at yu1994-ThinkPad-W520:~/tem$ cd build/
lerui at yu1994-ThinkPad-W520:~/tem/build$
PKG_CONFIG_PATH=$PETSC_DIR/$PETSC_ARCH/lib/pkgconfig cmake ..-- The C
compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for one of the modules 'PETSc'
pkg include dirs:
/home/lerui/petsc-3.12.2/arch-linux2-c-debug/include;/home/lerui/petsc-3.12.2/include
pkg include libs: petsc
pkg ldflags: -L/home/lerui/petsc-3.12.2/arch-linux2-c-debug/lib;-lpetsc
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lerui/tem/build
lerui at yu1994-ThinkPad-W520:~/tem/build$ make
Scanning dependencies of target example01cmke
[ 50%] Building CXX object CMakeFiles/example01cmke.dir/ex1.cpp.o
[100%] Linking CXX executable example01cmke
[100%] Built target example01cmke
lerui at yu1994-ThinkPad-W520:~/tem/build$ mpiexec -n 1 ./example01cmke
-snes_monitor
./example01cmke: error while loading shared libraries: libpetsc.so.3.12:
cannot open shared object file: No such file or directory
-------------------------------------------------------
Primary job  terminated normally, but 1 process returned
a non-zero exit code.. Per user-direction, the job has been aborted.
-------------------------------------------------------
--------------------------------------------------------------------------
mpiexec detected that one or more processes exited with non-zero status,
thus causing
the job to be terminated. The first process to do so was:

  Process name: [[6716,1],0]
  Exit code:    127
--------------------------------------------------------------------------

Thanks,
Yingjie

Jed Brown <jed at jedbrown.org> 于2019年12月5日周四 下午1:17写道:

> Yingjie Wu <yjwu16 at gmail.com> writes:
>
> > Hi,
> > I tried to use PKG to find the library file of PETSc, but there were some
> > errors. Because I am not very familiar with cmake, I refer to different
> PKG
> > tutorials. My CMakeList.txt is as follows. I don't know how to solve this
> > error message, please give me some suggestions.
> >
> > yjwu at yjwu-XPS-8910:~/PETSctest/Testcmake$ cat CMakeLists.txt
> > #This is a CMake makefile.
> > cmake_minimum_required(VERSION 2.8.11)
> >
> > project(example01cmke)
> >
> > add_executable(example01cmke ex1.cpp)
> >
> > find_package(PkgConfig REQUIRED)
> >
> > message("petsc directories: ${PETSC_DIR}")
> >
> > message("petsc arch: ${PETSC_ARCH}")
> >
> > set(ENV{PKG_CONFIG_PATH}
> > /home/yjwu/petsc-3.10.1/arch-linux2-c-debug/lib/pkgconfig)
> >
> > pkg_search_module(PETSC REQUIRED PETSc)
> >
> > message("pkg include dirs: ${PETSC_INCLUDE_DIRS}")
> >
> > message("pkg include libs: ${PETSC_LIBRARIES}")
> >
> > message("pkg ldflags: ${PETSC_LDFLAGS}")
> >
> > include_directories(${PETSC_INCLUDE_DIRS})
> >
> > target_link_libraries(example01cmke ${PETSC_LDFLAGS})
> >
> > yjwu at yjwu-XPS-8910:~/PETSctest/Testcmake$ cd build/
> > yjwu at yjwu-XPS-8910:~/PETSctest/Testcmake/build$ cmake ..
> > -- The C compiler identification is GNU 5.4.0
> > -- The CXX compiler identification is GNU 5.4.0
> > -- Check for working C compiler: /usr/bin/cc
> > -- Check for working C compiler: /usr/bin/cc -- works
> > -- Detecting C compiler ABI info
> > -- Detecting C compiler ABI info - done
> > -- Detecting C compile features
> > -- Detecting C compile features - done
> > -- Check for working CXX compiler: /usr/bin/c++
> > -- Check for working CXX compiler: /usr/bin/c++ -- works
> > -- Detecting CXX compiler ABI info
> > -- Detecting CXX compiler ABI info - done
> > -- Detecting CXX compile features
> > -- Detecting CXX compile features - done
> > -- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
> > petsc directories:
> > petsc arch:
> > -- Checking for one of the modules 'PETSc'
> > pkg include dirs:
> >
> /home/yjwu/petsc-3.10.1/include;/home/yjwu/petsc-3.10.1/arch-linux2-c-debug/include
> > pkg include libs: petsc
> > pkg ldflags: -L/home/yjwu/petsc-3.10.1/lib;-lpetsc
> > -- Configuring done
> > -- Generating done
> > -- Build files have been written to: /home/yjwu/PETSctest/Testcmake/build
> > yjwu at yjwu-XPS-8910:~/PETSctest/Testcmake/build$ make
> > Scanning dependencies of target example01cmke
> > [ 50%] Building CXX object CMakeFiles/example01cmke.dir/ex1.cpp.o
> > [100%] Linking CXX executable example01cmke
> > /usr/bin/ld: cannot find -lpetsc
> > collect2: error: ld returned 1 exit status
>
> Is your PETSc fully built/installed, or just configured?
>
> I just tested with this simplified file
>
> cmake_minimum_required(VERSION 2.8.11)
> project(example01cmke)
>
> add_executable(example01cmke ex1.cpp)
>
> find_package(PkgConfig REQUIRED)
> pkg_search_module(PETSC REQUIRED PETSc)
> message("pkg include dirs: ${PETSC_INCLUDE_DIRS}")
> message("pkg include libs: ${PETSC_LIBRARIES}")
> message("pkg ldflags: ${PETSC_LDFLAGS}")
>
> include_directories(${PETSC_INCLUDE_DIRS})
> target_link_libraries(example01cmke ${PETSC_LDFLAGS})
>
>
> $ PKG_CONFIG_PATH=$PETSC_DIR/$PETSC_ARCH/lib/pkgconfig cmake ..
> -- The C compiler identification is GNU 9.2.0
> -- The CXX compiler identification is GNU 9.2.0
> -- Check for working C compiler: /bin/cc
> -- Check for working C compiler: /bin/cc -- works
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> -- Detecting C compile features
> -- Detecting C compile features - done
> -- Check for working CXX compiler: /bin/c++
> -- Check for working CXX compiler: /bin/c++ -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> -- Found PkgConfig: /bin/pkg-config (found version "1.6.3")
> -- Checking for one of the modules 'PETSc'
> pkg include dirs: /home/jed/petsc/ompi-optg/include;/home/jed/petsc/include
> pkg include libs: petsc
> pkg ldflags: -L/home/jed/petsc/ompi-optg/lib;-lpetsc
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /tmp/jed/build
> 22:12 jedjoule12  /tmp/jed/build$ make
> Scanning dependencies of target example01cmke
> [ 50%] Building CXX object CMakeFiles/example01cmke.dir/ex1.cpp.o
> [100%] Linking CXX executable example01cmke
> [100%] Built target example01cmke
>
>
> Note that you may need to set RPATH (in CMake) or export a suitable
> LD_LIBRARY_PATH if your PETSc is in a non-standard location.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20191205/1ce61d5b/attachment-0001.html>


More information about the petsc-users mailing list