[petsc-users] CMake error in PETSc
Yingjie Wu
yjwu16 at gmail.com
Wed Dec 4 21:48:49 CST 2019
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
CMakeFiles/example01cmke.dir/build.make:94: recipe for target
'example01cmke' failed
make[2]: *** [example01cmke] Error 1
CMakeFiles/Makefile2:67: recipe for target
'CMakeFiles/example01cmke.dir/all' failed
make[1]: *** [CMakeFiles/example01cmke.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Thanks,
Yingjie
Jed Brown <jed at jedbrown.org> 于2019年12月5日周四 上午12:05写道:
> Yingjie Wu <yjwu16 at gmail.com> writes:
>
> > Thank you for your response.
> >
> > I have two questions about using FindPkgConfig:
> >
> >
> > 1. Is there any requirement for petsc version using FindPkgConfig? I'm
> > using an older version 3.10.1.
>
> 3.10 should be sufficient (though we recommend upgrading).
>
> > 2. Does the use of FindPkgConfig only require the following commands
> and
> > does not require any scripts?
>
> Correct, no scripts.
>
> > find_package(PkgConfig REQUIRED)
> >
> > pkg_search_module (PETSC REQUIRED PETSc)
> >
> > target_link_libraries(testapp ${PETSC_LIBRARIES})
> >
> > target_link_includes(testapp ${PETSC_INCLUDE_DIRS})
> >
> > Since I just came into contact with cmake, I really need some help.
> >
> >
> > Thanks,
> >
> > Yingjie
> >
> >
> > Jed Brown <jed at jedbrown.org> 于2019年12月4日周三 下午11:31写道:
> >
> >> Yingjie Wu <yjwu16 at gmail.com> writes:
> >>
> >> > Dear Petsc developers
> >> > Hi,
> >> > Because I use some external library files, I want to compile the PETSc
> >> > program with CMake. I follow the library search program
> >> >
> >>
> https://github.com/CoolProp/CoolProp/blob/b493de51a44078e4f5bbb8712e89305fd91f8b85/CMakeLists.txt
> >> > recommended
> >> > on GitHub. And wrote a cmakelist.txt:
> >> >
> >> > cmake_minimum_required(VERSION 2.8.11)
> >> > project(example01cmke)
> >> > add_executable(example01cmke ex1.cpp)
> >> > set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
> >> > find_package(PETSc)
> >> > include_directories(${PETSC_INCLUDE_DIR})
> >>
> >> This needs to be spelled PETSC_INCLUDES, as stated in FindPETSc.cmake.
> >>
> >> These days, I usually recommend that people use
> >>
> >> https://cmake.org/cmake/help/latest/module/FindPkgConfig.html
> >>
> >> instead of my FindPETSc.cmake because its simpler and doesn't require
> >> the script (which was developed before we added pkg-config support to
> >> PETSc).
> >>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20191205/725f5ac7/attachment-0001.html>
More information about the petsc-users
mailing list