<div dir="ltr">Hi,<div>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.<br></div><div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>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} /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: /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>CMakeFiles/example01cmke.dir/build.make:94: recipe for target 'example01cmke' failed<br>make[2]: *** [example01cmke] Error 1<br>CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/example01cmke.dir/all' failed<br>make[1]: *** [CMakeFiles/example01cmke.dir/all] Error 2<br>Makefile:83: recipe for target 'all' failed<br>make: *** [all] Error 2<br></div></blockquote></div><div><br></div><div>Thanks,</div><div>Yingjie</div><div><br></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日周四 上午12:05写道:<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>
> Thank you for your response.<br>
><br>
> I have two questions about using FindPkgConfig:<br>
><br>
><br>
> 1. Is there any requirement for petsc version using FindPkgConfig? I'm<br>
> using an older version 3.10.1.<br>
<br>
3.10 should be sufficient (though we recommend upgrading).<br>
<br>
> 2. Does the use of FindPkgConfig only require the following commands and<br>
> does not require any scripts?<br>
<br>
Correct, no scripts.<br>
<br>
> find_package(PkgConfig REQUIRED)<br>
><br>
> pkg_search_module (PETSC REQUIRED PETSc)<br>
><br>
> target_link_libraries(testapp ${PETSC_LIBRARIES})<br>
><br>
> target_link_includes(testapp ${PETSC_INCLUDE_DIRS})<br>
><br>
> Since I just came into contact with cmake, I really need some help.<br>
><br>
><br>
> Thanks,<br>
><br>
> Yingjie<br>
><br>
><br>
> Jed Brown <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>> 于2019年12月4日周三 下午11:31写道:<br>
><br>
>> Yingjie Wu <<a href="mailto:yjwu16@gmail.com" target="_blank">yjwu16@gmail.com</a>> writes:<br>
>><br>
>> > Dear Petsc developers<br>
>> > Hi,<br>
>> > Because I use some external library files, I want to compile the PETSc<br>
>> > program with CMake. I follow the library search program<br>
>> ><br>
>> <a href="https://github.com/CoolProp/CoolProp/blob/b493de51a44078e4f5bbb8712e89305fd91f8b85/CMakeLists.txt" rel="noreferrer" target="_blank">https://github.com/CoolProp/CoolProp/blob/b493de51a44078e4f5bbb8712e89305fd91f8b85/CMakeLists.txt</a><br>
>> > recommended<br>
>> > on GitHub. And wrote a cmakelist.txt:<br>
>> ><br>
>> > cmake_minimum_required(VERSION 2.8.11)<br>
>> > project(example01cmke)<br>
>> > add_executable(example01cmke ex1.cpp)<br>
>> > set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)<br>
>> > find_package(PETSc)<br>
>> > include_directories(${PETSC_INCLUDE_DIR})<br>
>><br>
>> This needs to be spelled PETSC_INCLUDES, as stated in FindPETSc.cmake.<br>
>><br>
>> These days, I usually recommend that people use<br>
>><br>
>> <a href="https://cmake.org/cmake/help/latest/module/FindPkgConfig.html" rel="noreferrer" target="_blank">https://cmake.org/cmake/help/latest/module/FindPkgConfig.html</a><br>
>><br>
>> instead of my FindPETSc.cmake because its simpler and doesn't require<br>
>> the script (which was developed before we added pkg-config support to<br>
>> PETSc).<br>
>><br>
</blockquote></div>