<div dir="ltr">Hi,<div><p style="margin:0px;white-space:pre-wrap">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:</p></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><p style="margin:0px;white-space:pre-wrap">lerui@yu1994-ThinkPad-W520:~/tem$ cat CMakeLists.txt <br>#This is a CMake makefile.<br>cmake_minimum_required(VERSION 2.8.11)<br><br>project(example01cmke)<br><br>add_executable(example01cmke ex1.cpp)<br><br>find_package(PkgConfig REQUIRED)<br><br>set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)<br><br>pkg_search_module(PETSC REQUIRED PETSc)<br><br>message("pkg include dirs: ${PETSC_INCLUDE_DIRS}")<br><br>message("pkg include libs: ${PETSC_LIBRARIES}")<br><br>message("pkg ldflags: ${PETSC_LDFLAGS}")<br><br>include_directories(${PETSC_INCLUDE_DIRS})<br><br>target_link_libraries(example01cmke ${PETSC_LDFLAGS})<br><br>lerui@yu1994-ThinkPad-W520:~/tem$ mkdir build<br>lerui@yu1994-ThinkPad-W520:~/tem$ cd build/<br>lerui@yu1994-ThinkPad-W520:~/tem/build$ PKG_CONFIG_PATH=$PETSC_DIR/$PETSC_ARCH/lib/pkgconfig cmake ..-- The C compiler identification is GNU 5.4.0<br>-- The CXX compiler identification is GNU 5.4.0<br>-- Check for working C compiler: /usr/bin/cc<br>-- Check for working C compiler: /usr/bin/cc -- works<br>-- Detecting C compiler ABI info<br>-- Detecting C compiler ABI info - done<br>-- Detecting C compile features<br>-- Detecting C compile features - done<br>-- Check for working CXX compiler: /usr/bin/c++<br>-- Check for working CXX compiler: /usr/bin/c++ -- works<br>-- Detecting CXX compiler ABI info<br>-- Detecting CXX compiler ABI info - done<br>-- Detecting CXX compile features<br>-- Detecting CXX compile features - done<br>-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") <br>-- Checking for one of the modules 'PETSc'<br>pkg include dirs: /home/lerui/petsc-3.12.2/arch-linux2-c-debug/include;/home/lerui/petsc-3.12.2/include<br>pkg include libs: petsc<br>pkg ldflags: -L/home/lerui/petsc-3.12.2/arch-linux2-c-debug/lib;-lpetsc<br>-- Configuring done<br>-- Generating done<br>-- Build files have been written to: /home/lerui/tem/build<br>lerui@yu1994-ThinkPad-W520:~/tem/build$ make<br>Scanning dependencies of target example01cmke<br>[ 50%] Building CXX object CMakeFiles/example01cmke.dir/ex1.cpp.o<br>[100%] Linking CXX executable example01cmke<br>[100%] Built target example01cmke<br>lerui@yu1994-ThinkPad-W520:~/tem/build$ mpiexec -n 1 ./example01cmke -snes_monitor<br>./example01cmke: error while loading shared libraries: libpetsc.so.3.12: cannot open shared object file: No such file or directory<br>-------------------------------------------------------<br>Primary job  terminated normally, but 1 process returned<br>a non-zero exit code.. Per user-direction, the job has been aborted.<br>-------------------------------------------------------<br>--------------------------------------------------------------------------<br>mpiexec detected that one or more processes exited with non-zero status, thus causing<br>the job to be terminated. The first process to do so was:<br><br>  Process name: [[6716,1],0]<br>  Exit code:    127<br>--------------------------------------------------------------------------<br></p></div></blockquote><span style="white-space:pre-wrap">Thanks,</span><div><span style="white-space:pre-wrap">Yingjie</span></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Jed Brown <<a href="mailto:jed@jedbrown.org">jed@jedbrown.org</a>> 于2019年12月5日周四 下午1:17写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Yingjie Wu <<a href="mailto:yjwu16@gmail.com" target="_blank">yjwu16@gmail.com</a>> writes:<br>
<br>
> Hi,<br>
> I tried to use PKG to find the library file of PETSc, but there were some<br>
> errors. Because I am not very familiar with cmake, I refer to different PKG<br>
> tutorials. My CMakeList.txt is as follows. I don't know how to solve this<br>
> error message, please give me some suggestions.<br>
><br>
> yjwu@yjwu-XPS-8910:~/PETSctest/Testcmake$ cat CMakeLists.txt<br>
> #This is a CMake makefile.<br>
> cmake_minimum_required(VERSION 2.8.11)<br>
><br>
> project(example01cmke)<br>
><br>
> add_executable(example01cmke ex1.cpp)<br>
><br>
> find_package(PkgConfig REQUIRED)<br>
><br>
> message("petsc directories: ${PETSC_DIR}")<br>
><br>
> message("petsc arch: ${PETSC_ARCH}")<br>
><br>
> set(ENV{PKG_CONFIG_PATH}<br>
> /home/yjwu/petsc-3.10.1/arch-linux2-c-debug/lib/pkgconfig)<br>
><br>
> pkg_search_module(PETSC REQUIRED PETSc)<br>
><br>
> message("pkg include dirs: ${PETSC_INCLUDE_DIRS}")<br>
><br>
> message("pkg include libs: ${PETSC_LIBRARIES}")<br>
><br>
> message("pkg ldflags: ${PETSC_LDFLAGS}")<br>
><br>
> include_directories(${PETSC_INCLUDE_DIRS})<br>
><br>
> target_link_libraries(example01cmke ${PETSC_LDFLAGS})<br>
><br>
> yjwu@yjwu-XPS-8910:~/PETSctest/Testcmake$ cd build/<br>
> yjwu@yjwu-XPS-8910:~/PETSctest/Testcmake/build$ cmake ..<br>
> -- The C compiler identification is GNU 5.4.0<br>
> -- The CXX compiler identification is GNU 5.4.0<br>
> -- Check for working C compiler: /usr/bin/cc<br>
> -- Check for working C compiler: /usr/bin/cc -- works<br>
> -- Detecting C compiler ABI info<br>
> -- Detecting C compiler ABI info - done<br>
> -- Detecting C compile features<br>
> -- Detecting C compile features - done<br>
> -- Check for working CXX compiler: /usr/bin/c++<br>
> -- Check for working CXX compiler: /usr/bin/c++ -- works<br>
> -- Detecting CXX compiler ABI info<br>
> -- Detecting CXX compiler ABI info - done<br>
> -- Detecting CXX compile features<br>
> -- Detecting CXX compile features - done<br>
> -- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")<br>
> petsc directories:<br>
> petsc arch:<br>
> -- Checking for one of the modules 'PETSc'<br>
> pkg include dirs:<br>
> /home/yjwu/petsc-3.10.1/include;/home/yjwu/petsc-3.10.1/arch-linux2-c-debug/include<br>
> pkg include libs: petsc<br>
> pkg ldflags: -L/home/yjwu/petsc-3.10.1/lib;-lpetsc<br>
> -- Configuring done<br>
> -- Generating done<br>
> -- Build files have been written to: /home/yjwu/PETSctest/Testcmake/build<br>
> yjwu@yjwu-XPS-8910:~/PETSctest/Testcmake/build$ make<br>
> Scanning dependencies of target example01cmke<br>
> [ 50%] Building CXX object CMakeFiles/example01cmke.dir/ex1.cpp.o<br>
> [100%] Linking CXX executable example01cmke<br>
> /usr/bin/ld: cannot find -lpetsc<br>
> collect2: error: ld returned 1 exit status<br>
<br>
Is your PETSc fully built/installed, or just configured?<br>
<br>
I just tested with this simplified file<br>
<br>
cmake_minimum_required(VERSION 2.8.11)<br>
project(example01cmke)<br>
<br>
add_executable(example01cmke ex1.cpp)<br>
<br>
find_package(PkgConfig REQUIRED)<br>
pkg_search_module(PETSC REQUIRED PETSc)<br>
message("pkg include dirs: ${PETSC_INCLUDE_DIRS}")<br>
message("pkg include libs: ${PETSC_LIBRARIES}")<br>
message("pkg ldflags: ${PETSC_LDFLAGS}")<br>
<br>
include_directories(${PETSC_INCLUDE_DIRS})<br>
target_link_libraries(example01cmke ${PETSC_LDFLAGS})<br>
<br>
<br>
$ PKG_CONFIG_PATH=$PETSC_DIR/$PETSC_ARCH/lib/pkgconfig cmake ..<br>
-- The C compiler identification is GNU 9.2.0<br>
-- The CXX compiler identification is GNU 9.2.0<br>
-- Check for working C compiler: /bin/cc<br>
-- Check for working C compiler: /bin/cc -- works<br>
-- Detecting C compiler ABI info<br>
-- Detecting C compiler ABI info - done<br>
-- Detecting C compile features<br>
-- Detecting C compile features - done<br>
-- Check for working CXX compiler: /bin/c++<br>
-- Check for working CXX compiler: /bin/c++ -- works<br>
-- Detecting CXX compiler ABI info<br>
-- Detecting CXX compiler ABI info - done<br>
-- Detecting CXX compile features<br>
-- Detecting CXX compile features - done<br>
-- Found PkgConfig: /bin/pkg-config (found version "1.6.3") <br>
-- Checking for one of the modules 'PETSc'<br>
pkg include dirs: /home/jed/petsc/ompi-optg/include;/home/jed/petsc/include<br>
pkg include libs: petsc<br>
pkg ldflags: -L/home/jed/petsc/ompi-optg/lib;-lpetsc<br>
-- Configuring done<br>
-- Generating done<br>
-- Build files have been written to: /tmp/jed/build<br>
22:12 jedjoule12  /tmp/jed/build$ make<br>
Scanning dependencies of target example01cmke<br>
[ 50%] Building CXX object CMakeFiles/example01cmke.dir/ex1.cpp.o<br>
[100%] Linking CXX executable example01cmke<br>
[100%] Built target example01cmke<br>
<br>
<br>
Note that you may need to set RPATH (in CMake) or export a suitable<br>
LD_LIBRARY_PATH if your PETSc is in a non-standard location.<br>
</blockquote></div>