The problem is that your Cmake file knows nothing about the MPI compilers
that are required and hence just selects some random compilers it found in the
path which do not support MPI.
I have attached a new CMakeList.txt for you to try.
I uses the environmental variables PETSC_DIR and PETSC_ARCH to find the
configuration file AND use the compilers from the configuration file. It works
for me, please let me know if you have trouble.
Barry
> On Dec 8, 2019, at 10:38 PM, Yingjie Wu <[email protected]> wrote:
>
> Thank you very much for your help.
> My programs are as follow
> Smith, Barry F. <[email protected]> 于2019年12月9日周一 下午12:29写道:
>
> There is something missing in the cmake process that is causing needed
> libraries not to be linked.
>
> Please email your program and your CMake stuff (files you use) so we can
> reproduce the problem and find a fix.
>
> Barry
>
>
> > On Dec 8, 2019, at 10:06 PM, Yingjie Wu <[email protected]> wrote:
> >
> > Hi,
> > Thank you for your response.
> > This problem has not been solved. I've been reporting errors in the process
> > of 'make'. The test example I used comes from: /snes /example
> > /tutorials/ex3.c by modifying the suffix of ex3, there will be different
> > error messages as following. I checked a lot of DSO problems on the
> > Internet and installed a lot of libraries, but the error still haven't been
> > solved. I was wondering if I was missing any prefix during the configure of
> > PETSc(I use the simplest recommended installation), but there was no
> > problem when the program was compiled with the 'makefile' which is
> > recommended. Because I need some extra libraries, I have to use cmake.
> > with ex3.c:
> > yjwu@yjwu-XPS-8910:~/tem/build2$ make
> > Scanning dependencies of target Test1
> > [ 50%] Building C object CMakeFiles/Test1.dir/ex3.c.o
> > [100%] Linking C executable Test1
> > /usr/bin/ld: CMakeFiles/Test1.dir/ex3.c.o: undefined reference to symbol
> > 'pow@@GLIBC_2.2.5'
> > //lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from
> > command line
> > collect2: error: ld returned 1 exit status
> > CMakeFiles/Test1.dir/build.make:94: recipe for target 'Test1' failed
> > make[2]: *** [Test1] Error 1
> > CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Test1.dir/all' failed
> > make[1]: *** [CMakeFiles/Test1.dir/all] Error 2
> > Makefile:83: recipe for target 'all' failed
> > make: *** [all] Error 2
> > with ex3.cpp:
> > yjwu@yjwu-XPS-8910:~/tem/build2$ make
> > Scanning dependencies of target Test1
> > [ 50%] Building CXX object CMakeFiles/Test1.dir/ex3.cpp.o
> > [100%] Linking CXX executable Test1
> > /usr/bin/ld: CMakeFiles/Test1.dir/ex3.cpp.o: undefined reference to symbol
> > 'MPI_Comm_rank'
> > /home/yjwu/petsc-3.12.2/arch-linux2-c-debug/lib/libmpi.so.12: error adding
> > symbols: DSO missing from command line
> > collect2: error: ld returned 1 exit status
> > CMakeFiles/Test1.dir/build.make:94: recipe for target 'Test1' failed
> > make[2]: *** [Test1] Error 1
> > CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Test1.dir/all' failed
> > make[1]: *** [CMakeFiles/Test1.dir/all] Error 2
> > Makefile:83: recipe for target 'all' failed
> > make: *** [all] Error 2
> > Thanks,
> > Yingjie
> >
> > Matthew Knepley <[email protected]> 于2019年12月6日周五 下午11:46写道:
> > It sounds like your C++ compiler is name mangling the symbol, but the
> > library has no mangling.
> > Why are you using C++.
> >
> > Thanks,
> >
> > Matt
> >
> > On Fri, Dec 6, 2019 at 10:44 AM Yingjie Wu <[email protected]> wrote:
> > Hi,
> > Thank you for your email.
> > The error in the previous program was indeed due to the missing
> > "SNESSetFromOptions".
> > I use the /snes/example/tutorial/ex1.cpp as test case. However, I found
> > that some of the statements in the program were not compiled and deleted
> > the statements containing "MPI_Comm_size", but I don't know how to solve
> > this problem.
> > lerui@yu1994-ThinkPad-W520:~/tem2/build2$ 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/tem2/build2
> > lerui@yu1994-ThinkPad-W520:~/tem2/build2$ make
> > Scanning dependencies of target main
> > [ 50%] Building CXX object CMakeFiles/main.dir/ex1.cpp.o
> > [100%] Linking CXX executable main
> > /usr/bin/ld: CMakeFiles/main.dir/ex1.cpp.o: undefined reference to symbol
> > 'MPI_Comm_size'
> > /home/lerui/petsc-3.12.2/arch-linux2-c-debug/lib/libmpi.so.12: error adding
> > symbols: DSO missing from command line
> > collect2: error: ld returned 1 exit status
> > CMakeFiles/main.dir/build.make:94: recipe for target 'main' failed
> > make[2]: *** [main] Error 1
> > CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/main.dir/all' failed
> > make[1]: *** [CMakeFiles/main.dir/all] Error 2
> > Makefile:83: recipe for target 'all' failed
> > make: *** [all] Error 2
> > Thanks,
> > Yingjie
> >
> > Jed Brown <[email protected]> 于2019年12月6日周五 上午10:54写道:
> > Yingjie Wu <[email protected]> writes:
> >
> > > 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.
> >
> > You can configure PETSc with --prefix=/your/standard/path, then make
> > install.
> >
> > > 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?
> >
> > I don't have your ex1.cpp, but presumably you didn't SNESSetFromOptions?
> >
> >
> > --
> > What most experimenters take for granted before they begin their
> > experiments is infinitely more interesting than any results to which their
> > experiments lead.
> > -- Norbert Wiener
> >
> > https://www.cse.buffalo.edu/~knepley/
>
> <CMakeLists.txt><ex3.cpp>
#This is a CMake makefile.
cmake_minimum_required(VERSION 2.8.11)
add_executable(Test1 ex3.cpp)
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)
# this must appear AFTER the compilers are set
project(Test1)
find_package(PkgConfig REQUIRED)
pkg_search_module(PETSC REQUIRED PETSc)
include_directories(${PETSC_INCLUDE_DIRS})
target_link_libraries(Test1 ${PETSC_LDFLAGS} pthread)