I'm so sorry that I've ignored your previous advices. I added a global variable that seems works:
export LD_LIBRARY_PATH=/home/lerui/petcs-3.12.2/arch-linux2-c-debug/lib:$LD_LIBRARY_PATH How should I make petsc in a standard position?This eliminates the need to set global variables. It seems that some of the options before running fit become unavailable: mpiexec -n 1 ./example01cmke -snes_view Options-snes _ view are not used and how should I solve this problem? Thank you for your response. Yingjie Yingjie Wu <yjw...@gmail.com> 于2019年12月5日周四 下午9:25写道: > 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@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@yu1994-ThinkPad-W520:~/tem$ mkdir build > lerui@yu1994-ThinkPad-W520:~/tem$ cd build/ > 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 > -- 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@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@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 <j...@jedbrown.org> 于2019年12月5日周四 下午1:17写道: > >> Yingjie Wu <yjw...@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@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@yjwu-XPS-8910:~/PETSctest/Testcmake$ cd build/ >> > yjwu@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@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. >> >