<div dir="ltr">Let me send this again for completeness -- left out a couple steps the first time:<div><br></div><div><div>$ cat ../CMakeLists.txt</div><div>cmake_minimum_required(VERSION 3.7)</div><div>project(main)</div><div><br></div><div>enable_language(CXX)</div><div>find_package(MPI REQUIRED)</div><div><br></div><div>find_package(PkgConfig REQUIRED)</div><div>pkg_check_modules(PETSc REQUIRED PETSc)</div><div><br></div><div># RPATH variables must be set, and link_directories called. before calling add_executable.</div><div>SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)</div><div>SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:$ORIGIN/../lib:${PETSc_LIBRARY_DIRS}")</div><div>set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-new-dtags")</div><div>set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-new-dtags")</div><div>set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-new-dtags")</div><div>link_directories(${PETSc_LIBRARY_DIRS})</div><div><br></div><div>add_executable(main main.cpp)</div><div><br></div><div>target_include_directories(main PUBLIC ${MPI_CXX_INCLUDE_PATH} ${PETSc_INCLUDE_DIRS})</div><div>target_link_libraries(main PUBLIC ${MPI_CXX_LIBRARIES} ${PETSc_LIBRARIES})</div><div><br></div><div>install(TARGETS main RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)</div></div><div><br></div><div><div>$ rm -rf * && cmake -DCMAKE_INSTALL_PREFIX=${HOME}/petsc-test ..</div><div>-- The C compiler identification is GNU 5.5.0</div><div>-- The CXX compiler identification is GNU 5.5.0</div><div>-- Check for working C compiler: /usr/bin/cc</div><div>-- Check for working C compiler: /usr/bin/cc -- works</div><div>-- Detecting C compiler ABI info</div><div>-- Detecting C compiler ABI info - done</div><div>-- Detecting C compile features</div><div>-- Detecting C compile features - done</div><div>-- Check for working CXX compiler: /usr/local/bin/c++</div><div>-- Check for working CXX compiler: /usr/local/bin/c++ -- works</div><div>-- Detecting CXX compiler ABI info</div><div>-- Detecting CXX compiler ABI info - done</div><div>-- Detecting CXX compile features</div><div>-- Detecting CXX compile features - done</div><div>-- Found MPI_C: /usr/lib/libmpi.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libhwloc.so</div><div>-- Found MPI_CXX: /usr/lib/libmpi_cxx.so;/usr/lib/libmpi.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libhwloc.so</div><div>-- Found PkgConfig: /usr/bin/pkg-config (found version "0.28")</div><div>-- Checking for module 'PETSc'</div><div>--   Found PETSc, version 3.8.3</div><div>-- Configuring done</div><div>-- Generating done</div><div>-- Build files have been written to: /home/dhinton/test/build</div></div><div><br></div><div><div>$ make VERBOSE=1</div><div>/usr/local/bin/cmake -H/home/dhinton/test -B/home/dhinton/test/build --check-build-system CMakeFiles/Makefile.cmake 0</div><div>/usr/local/bin/cmake -E cmake_progress_start /home/dhinton/test/build/CMakeFiles /home/dhinton/test/build/CMakeFiles/progress.marks</div><div>make -f CMakeFiles/Makefile2 all</div><div>make[1]: Entering directory '/home/dhinton/test/build'</div><div>make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/depend</div><div>make[2]: Entering directory '/home/dhinton/test/build'</div><div>cd /home/dhinton/test/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/dhinton/test /home/dhinton/test /home/dhinton/test/build /home/dhinton/test/build /home/dhinton/test/build/CMakeFiles/main.dir/DependInfo.cmake --color=</div><div>Dependee "/home/dhinton/test/build/CMakeFiles/main.dir/DependInfo.cmake" is newer than depender "/home/dhinton/test/build/CMakeFiles/main.dir/depend.internal".</div><div>Dependee "/home/dhinton/test/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/dhinton/test/build/CMakeFiles/main.dir/depend.internal".</div><div>Scanning dependencies of target main</div><div>make[2]: Leaving directory '/home/dhinton/test/build'</div><div>make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build</div><div>make[2]: Entering directory '/home/dhinton/test/build'</div><div>[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o</div><div>/usr/local/bin/c++   -I/usr/lib/openmpi/include -I/usr/lib/openmpi/include/openmpi -I/home/dhinton/usr/include   -o CMakeFiles/main.dir/main.cpp.o -c /home/dhinton/test/main.cpp</div><div>[100%] Linking CXX executable main</div><div>/usr/local/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1</div><div>/usr/local/bin/c++     -Wl,--enable-new-dtags CMakeFiles/main.dir/main.cpp.o  -o main  -L/home/dhinton/usr/lib -Wl,-rpath,":\$ORIGIN/../lib:/home/dhinton/usr/lib" /usr/lib/libmpi_cxx.so /usr/lib/libmpi.so /usr/lib/x86_64-linux-gnu/libdl.so /usr/lib/x86_64-linux-gnu/libhwloc.so -lpetsc</div><div>make[2]: Leaving directory '/home/dhinton/test/build'</div><div>[100%] Built target main</div><div>make[1]: Leaving directory '/home/dhinton/test/build'</div><div>/usr/local/bin/cmake -E cmake_progress_start /home/dhinton/test/build/CMakeFiles 0</div></div><div><br></div><div><div>$ objdump -x main | grep PATH</div><div>  RUNPATH              :$ORIGIN/../lib:/home/dhinton/usr/lib</div></div><div><br></div><div><div>$ objdump -x main | grep PATH</div><div>  RUNPATH              :$ORIGIN/../lib:/home/dhinton/usr/lib</div><div>a5459ba277d5:/home/dhinton/test/build $ make install</div><div>[100%] Built target main</div><div>Install the project...</div><div>-- Install configuration: ""</div><div>-- Installing: /home/dhinton/petsc-test/bin/main</div></div><div><br></div><div><div>$ objdump -x ~/petsc-test/bin/main | grep PATH</div><div>  RUNPATH              :$ORIGIN/../lib:/home/dhinton/usr/lib</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 4, 2018 at 12:49 PM, Don Hinton <span dir="ltr"><<a href="mailto:hintonda@gmail.com" target="_blank">hintonda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This is mostly an ordering problem -- you need to setup everything before calling add_executable.  Also, I was wrong about using ';' in RPATH variables.  They should use ':' as in your original since they are used verbatim.<div><br></div><div>Here's an example that works:<div><br></div><div><div>$ cat ../CMakeLists.txt</div><div>cmake_minimum_required(VERSION 3.7)</div><div>project(main)</div><span class=""><div><br></div><div>enable_language(CXX)</div><div>find_package(MPI REQUIRED)</div><div><br></div><div>find_package(PkgConfig REQUIRED)</div></span><div>pkg_check_modules(PETSc REQUIRED PETSc)</div><div><br></div><div># RPATH variables must be set, and link_directories called. before calling add_executable.</div><div>SET(CMAKE_BUILD_WITH_INSTALL_<wbr>RPATH TRUE)</div><div>SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:$<wbr>ORIGIN/../lib:${PETSc_LIBRARY_<wbr>DIRS}")</div><div>set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-new-dtags")</div><div>set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-new-dtags")</div><div>set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-new-dtags")</div><div>link_directories(${PETSc_<wbr>LIBRARY_DIRS})</div><div><br></div><div>add_executable(main main.cpp)</div><div><br></div><div>target_include_directories(<wbr>main PUBLIC ${MPI_CXX_INCLUDE_PATH} ${PETSc_INCLUDE_DIRS})</div><div>target_link_libraries(main PUBLIC ${MPI_CXX_LIBRARIES} ${PETSc_LIBRARIES})</div><div><br></div><div>install(TARGETS main RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)</div></div><div><br></div><div><div>$ make VERBOSE=1</div><div>/usr/local/bin/cmake -H/home/dhinton/test -B/home/dhinton/test/build --check-build-system CMakeFiles/Makefile.cmake 0</div><div>/usr/local/bin/cmake -E cmake_progress_start /home/dhinton/test/build/<wbr>CMakeFiles /home/dhinton/test/build/<wbr>CMakeFiles/progress.marks</div><div>make -f CMakeFiles/Makefile2 all</div><div>make[1]: Entering directory '/home/dhinton/test/build'</div><div>make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/depend</div><div>make[2]: Entering directory '/home/dhinton/test/build'</div><div>cd /home/dhinton/test/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/dhinton/test /home/dhinton/test /home/dhinton/test/build /home/dhinton/test/build /home/dhinton/test/build/<wbr>CMakeFiles/main.dir/<wbr>DependInfo.cmake --color=</div><div>make[2]: Leaving directory '/home/dhinton/test/build'</div><div>make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build</div><div>make[2]: Entering directory '/home/dhinton/test/build'</div><div>make[2]: Nothing to be done for 'CMakeFiles/main.dir/build'.</div><div>make[2]: Leaving directory '/home/dhinton/test/build'</div><div>[100%] Built target main</div><div>make[1]: Leaving directory '/home/dhinton/test/build'</div><div>/usr/local/bin/cmake -E cmake_progress_start /home/dhinton/test/build/<wbr>CMakeFiles 0</div></div><div><br></div><div><div>$ objdump -x main | grep PATH</div><div>  RUNPATH              :$ORIGIN/../lib:/home/dhinton/<wbr>usr/lib</div></div><div><br></div><div><div>$ make install</div><div>[100%] Built target main</div><div>Install the project...</div><div>-- Install configuration: ""</div><div>-- Installing: /home/dhinton/petsc-test/bin/<wbr>main</div></div><div><br></div><div><div>$ objdump -x ~/petsc-test/bin/main | grep PATH</div><div>  RUNPATH              :$ORIGIN/../lib:/home/dhinton/<wbr>usr/lib</div></div><div><br></div><div>hth...</div><span class="HOEnZb"><font color="#888888"><div>don</div></font></span></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 4, 2018 at 9:13 AM, Franck Houssen <span dir="ltr"><<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div><div>not working with the last cmakelist I have which is:</div><div><br></div>>> more ../CMakeLists.txt <br><span>cmake_minimum_required(VERSION 3.7)<br>enable_language(CXX)<br><br>find_package(MPI REQUIRED)<br>find_package(PkgConfig REQUIRED) # Get pkg_check_modules.<br>pkg_check_modules(PETSc REQUIRED PETSc)<br><br>project(main)<br>add_executable(main main.cpp)<br><br>target_include_directories(mai<wbr>n PUBLIC ${MPI_CXX_INCLUDE_PATH})<br>target_link_libraries(main PUBLIC ${MPI_CXX_LIBRARIES})<br><br>target_include_directories(mai<wbr>n PUBLIC ${PETSc_INCLUDE_DIRS})<br>foreach(lib ${PETSc_LDFLAGS})<br>  target_link_libraries(main PUBLIC ${lib})<br></span><span>  message("target_link_libraries - lib is ${lib}")<br>endforeach(lib)<br><br></span><span># use, i.e. don't skip the full RPATH for the build tree<br>SET(CMAKE_SKIP_BUILD_RPATH  FALSE)<br># when building, don't use the install RPATH already<br># (but later on when installing)<br></span>SET(CMAKE_BUILD_WITH_INSTALL_R<wbr>PATH TRUE)<br>SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;$<wbr>{CMAKE_INSTALL_RPATH}")<span><br># add the automatically determined parts of the RPATH<br># which point to directories outside the build tree to the install RPATH<br>SET(CMAKE_INSTALL_RPATH_USE_LI<wbr>NK_PATH TRUE)<br># the RPATH to be used when installing, but only if it's not a system directory<br>LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_D<wbr>IRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)<br></span><span>IF("${isSystemDir}" STREQUAL "-1")<br></span>   SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;$<wbr>{CMAKE_INSTALL_RPATH}")<span><br>ENDIF("${isSystemDir}" STREQUAL "-1")<br></span><span>foreach(dir ${PETSc_LIBRARY_DIRS})<br>  link_directories(main PUBLIC ${dir})<br>  message("link_directories - dir is ${dir}")<br>  set(CMAKE_INSTALL_RPATH "${dir};${CMAKE_INSTALL_RPATH}<wbr>")<br>endforeach(dir)<br></span>message("CMAKE_INSTALL_RPATH: ${CMAKE_INSTALL_RPATH}")<span><br><br>include(CTest)<br>enable_testing()<br>add_test(NAME main COMMAND "mpirun -n 2 ./main" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")</span></div><div><br></div><hr id="m_-3029531158353346168m_-6299860555380368388zwchr"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><span><b>De: </b>"Don Hinton" <<a href="mailto:hintonda@gmail.com" target="_blank">hintonda@gmail.com</a>><br><b>À: </b>"Franck Houssen" <<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>><br></span><b>Cc: </b>"Andreas Naumann" <<a href="mailto:Andreas-Naumann@gmx.net" target="_blank">Andreas-Naumann@gmx.net</a>>, "CMake Mail List" <<a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a>><br><b>Envoyé: </b>Jeudi 4 Janvier 2018 17:47:19<div><div class="m_-3029531158353346168h5"><br><b>Objet: </b>Re: [CMake] RPATH for pkg-config<br><div><br></div><div dir="ltr">Are you still doing this at the end?  You are overwriting here, not adding.<div><br></div><div><span style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif">IF("${isSystemDir}" STREQUAL "-1")</span><br style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif"><span style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif">   SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")</span><br style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif"><span style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif">ENDIF("${isSystemDir}" STREQUAL "-1")</span><br></div><div><span style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif"><br></span></div><div><span style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif">Also, do not use ':', use ';' instead as a separator.  Or use 'list(APPEND ...), to add to a list.</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 4, 2018 at 8:34 AM, Franck Houssen <span dir="ltr"><<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>nope !... :D<br></div><div><br></div><hr id="m_-3029531158353346168m_-6299860555380368388m_-1436670033624782906zwchr"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><span><b>De: </b>"Don Hinton" <<a href="mailto:hintonda@gmail.com" target="_blank">hintonda@gmail.com</a>><br><b>À: </b>"Franck Houssen" <<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>><br><b>Cc: </b>"Andreas Naumann" <<a href="mailto:Andreas-Naumann@gmx.net" target="_blank">Andreas-Naumann@gmx.net</a>>, <a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a><br></span><b>Envoyé: </b>Jeudi 4 Janvier 2018 16:52:53<span><br><b>Objet: </b>Re: [CMake] RPATH for pkg-config<br><div><br></div><div><br><div class="gmail_quote"><div dir="auto">On Thu, Jan 4, 2018 at 3:57 AM Franck Houssen <<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><hr id="m_-3029531158353346168m_-6299860555380368388m_-1436670033624782906m_-4529413231888781811zwchr"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>De: </b>"Don Hinton" <<a href="mailto:hintonda@gmail.com" target="_blank">hintonda@gmail.com</a>><br><b>À: </b>"Franck Houssen" <<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>><br><b>Cc: </b>"Andreas Naumann" <<a href="mailto:Andreas-Naumann@gmx.net" target="_blank">Andreas-Naumann@gmx.net</a>>, <a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a><br><b>Envoyé: </b>Jeudi 4 Janvier 2018 10:43:28</blockquote></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><br><b>Objet: </b>Re: [CMake] RPATH for pkg-config<br><div><br></div><div><div dir="auto">The cmake rpath settings handle build/install directories more or less automatically, but you need to add a completely different path.</div></div></blockquote></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div><br></div><div>Yes. That's the problem: I need to add a completely different path.<br></div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div><br></div><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div><div dir="auto"><br></div><div dir="auto">Try adding the additional path (pretty much every -L you added) to CMAKE_INSTALL_RPATH, and set CMAKE_BUILD_WITH_INSTALL_RPATH<wbr>=TRUE.</div></div></blockquote><div><br></div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>See does not work<br></div><div><br></div><div>>> more ../CMakeLists.txt <br>...</div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div><br>foreach(dir ${PETSc_LIBRARY_DIRS})<br>  link_directories(main PUBLIC ${dir})<br>  message("link_directories - dir is ${dir}")<br>  set(CMAKE_INSTALL_RPATH "${dir}:${CMAKE_INSTALL_RPATH}<wbr>")<br>endforeach(dir)</div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">s/:/;/</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div><br></div></div></div></blockquote><div dir="auto">You need to use a semicolon instead is a colon as a cmake list separator.</div></div></div></span></blockquote><div><br></div><div><br></div><div>I wish it could have worked. Don't understand.<br></div><div><br></div><div>I added a message<br></div><span><div><br></div><div>>> cmake ..; make VERBOSE=1<br>...<br></div></span><div><span>target_link_libraries - lib is -L/home/fghoussen/Documents/IN<wbr>RIA/petsc/local/lib<br>target_link_libraries - lib is -lpetsc<br>link_directories - dir is /home/fghoussen/Documents/INRI<wbr>A/petsc/local/lib<br></span>CMAKE_INSTALL_RPATH: /home/fghoussen/Documents/INRI<wbr>A/petsc/local/lib;/usr/local/<wbr>lib;/usr/local/lib;<br>...<br></div><div>>> ldd main<br></div><div>    linux-vdso.so.1 (0x00007ffdec8e8000)<br>    libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libm<wbr>pi_cxx.so.20 (0x00007f429a28a000)<br>    libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libm<wbr>pi.so.20 (0x00007f4299f94000)<br>    libpetsc.so.3.8 => not found<br><div><br></div></div><div><div class="m_-3029531158353346168m_-6299860555380368388h5"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div><div class="gmail_quote"><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div><br></div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>...</div><div>SET(CMAKE_BUILD_WITH_INSTALL_R<wbr>PATH TRUE)<br>...<br></div><div><br></div><div>>> cmake ..; make VERBOSE=1<br></div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>...<br>target_link_libraries - lib is -L/home/fghoussen/Documents/IN<wbr>RIA/petsc/local/lib<br>target_link_libraries - lib is -lpetsc<br>link_directories - dir is /home/fghoussen/Documents/INRI<wbr>A/petsc/local/lib</div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>...<br>[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o<br>/usr/bin/c++   -I/usr/lib/x86_64-linux-gnu/op<wbr>enmpi/include/openmpi -I/usr/lib/x86_64-linux-gnu/op<wbr>enmpi/include/openmpi/opal/mca<wbr>/event/libevent2022/libevent -I/usr/lib/x86_64-linux-gnu/op<wbr>enmpi/include/openmpi/opal/mca<wbr>/event/libevent2022/libevent/<wbr>include -I/usr/lib/x86_64-linux-gnu/op<wbr>enmpi/include -I/home/fghoussen/Documents/IN<wbr>RIA/petsc/local/include   -o CMakeFiles/main.dir/main.cpp.o -c /home/fghoussen/Downloads/cmak<wbr>e/rpath-pkgconfig/main.cpp<br>[100%] Linking CXX executable main<br>/usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1<br>/usr/bin/c++     CMakeFiles/main.dir/main.cpp.o<wbr>  -o main -Wl,-rpath,/usr/lib/x86_64-lin<wbr>ux-gnu/openmpi/lib /usr/lib/x86_64-linux-gnu/open<wbr>mpi/lib/libmpi_cxx.so /usr/lib/x86_64-linux-gnu/open<wbr>mpi/lib/libmpi.so -L/home/fghoussen/Documents/IN<wbr>RIA/petsc/local/lib -lpetsc <br>make[2]: Leaving directory '/home/fghoussen/Downloads/cma<wbr>ke/rpath-pkgconfig/BUILD'<br>[100%] Built target main<br>make[1]: Leaving directory '/home/fghoussen/Downloads/cma<wbr>ke/rpath-pkgconfig/BUILD'<br>/usr/bin/cmake -E cmake_progress_start /home/fghoussen/Downloads/cmak<wbr>e/rpath-pkgconfig/BUILD/CMakeF<wbr>iles 0<br></div><div><br></div><div>>> ldd main<br></div><div>    linux-vdso.so.1 (0x00007ffcd876b000)<br>    libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libm<wbr>pi_cxx.so.20 (0x00007f9eaba1f000)<br>    libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libm<wbr>pi.so.20 (0x00007f9eab729000)<br>    libpetsc.so.3.8 => not found<br><div><br></div><br></div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div><div dir="auto">Then run cmake with the ‘-v’ option and look at the link command to verify rpath was passed correctly.</div><div dir="auto"><br></div><div dir="auto">You can also examine it in a library or executable with ‘objdump-x’.</div><div dir="auto"><br></div><div dir="auto">You may want to customize this for your project, but this should get you started.</div><div dir="auto"><br></div><div dir="auto">hth...</div><div dir="auto">don</div><br><div class="gmail_quote"><div>On Thu, Jan 4, 2018 at 1:25 AM Franck Houssen <<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">My understanding is that you need a local copy of FindPETSc.cmake: if this changes, you don't know it.<br> That's why I tried to go with the pc file.<br><div><br></div>----- Mail original -----<br> > De: "Andreas Naumann" <<a href="mailto:Andreas-Naumann@gmx.net" target="_blank">Andreas-Naumann@gmx.net</a>><br> > À: <a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a><br> > Envoyé: Mercredi 3 Janvier 2018 21:41:51<br> > Objet: Re: [CMake] RPATH for pkg-config<br> ><br> > What about using a FindPETSC-Module? Some hints are<br> >      *<a href="http://jacobmerson.com/2016/01/17/cmake-petsc2.html" rel="noreferrer" target="_blank">http://jacobmerson.com/2016/0<wbr>1/17/cmake-petsc2.html</a><br> >      *<a href="http://www.mcs.anl.gov/petsc/documentation/faq.html#cmake" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/<wbr>documentation/faq.html#cmake</a><br> ><br> > Regards,<br> > Andreas<br> ><br> > Am 03.01.2018 um 21:35 schrieb Alexander Neundorf:<br> > > On 2018 M01 3, Wed 10:08:09 CET Franck Houssen wrote:<br> > >> Hello,<br> > >><br> > >> How to ask cmake to add a library path (coming from pc file) to rpath ?<br> > >><br> > >> I checked this <a href="https://cmake.org/Wiki/CMake_RPATH_handling" rel="noreferrer" target="_blank">https://cmake.org/Wiki/CMake_R<wbr>PATH_handling</a>, but still not<br> > >> working. Can somebody help ?<br> > >>>> more main.cpp<br> > >> #include <petsc.h><br> > >><br> > >> int main(int argc, char ** argv) {<br> > >> PetscInitialize(&argc, &argv, NULL, "");<br> > >> PetscFinalize();<br> > >> return 0;<br> > >> }<br> > >><br> > >>>> more CMakeLists.txt<br> > >> cmake_minimum_required(VERSION 3.7)<br> > >> enable_language(CXX)<br> > >><br> > >> find_package(MPI REQUIRED)<br> > >> find_package(PkgConfig REQUIRED) # Get pkg_check_modules.<br> > >> pkg_check_modules(PETSc REQUIRED PETSc)<br> > >><br> > >> project(main)<br> > >> add_executable(main main.cpp)<br> > >><br> > >> target_include_directories(mai<wbr>n PUBLIC ${MPI_CXX_INCLUDE_PATH})<br> > >> target_link_libraries(main PUBLIC ${MPI_CXX_LIBRARIES})<br> > >><br> > >> target_include_directories(mai<wbr>n PUBLIC ${PETSc_INCLUDE_DIRS})<br> > >> foreach(lib ${PETSc_LDFLAGS})<br> > >> target_link_libraries(main PUBLIC ${lib})<br> > >> endforeach(lib)<br> > > How does each ${lib} look like ?<br> > > Is it "-lpetsc" or does it have the full path to the libraries ?<br> > > You should use the full path to the libraries, otherwise cmake doesn't know<br> > > where they are and the RPATH computation will not work.<br> > ><br> > >> foreach(dir ${PETSc_LIBRARY_DIRS})<br> > >> link_directories(main PUBLIC ${dir}) # Not sure: is this needed ?<br> > >> endforeach(dir)<br> > > no, link_directories() in general should not be used.<br> > ><br> > >> # use, i.e. don't skip the full RPATH for the build tree<br> > >> SET(CMAKE_SKIP_BUILD_RPATH FALSE)<br> > >> # when building, don't use the install RPATH already<br> > >> # (but later on when installing)<br> > >> SET(CMAKE_BUILD_WITH_INSTALL_R<wbr>PATH FALSE)<br> > >> SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")<br> > > If the automatic computation fails, you could add the petsc lib dir here as<br> > > INSTALL_RPATH<br> > ><br> > > Alex<br> > ><br> ><br> > --<br> ><br> > Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br> ><br> > Please keep messages on-topic and check the CMake FAQ at:<br> > <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMak<wbr>e_FAQ</a><br> ><br> > Kitware offers various services to support the CMake community. For more<br> > information on each offering, please visit:<br> ><br> > CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/su<wbr>pport.html</a><br> > CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/co<wbr>nsulting.html</a><br> > CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/tr<wbr>aining.html</a><br> ><br> > Visit other Kitware open-source projects at<br> > <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensou<wbr>rce/opensource.html</a><br> ><br> > Follow this link to subscribe/unsubscribe:<br> > <a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/list<wbr>info/cmake</a><br> ><br> --<br><div><br></div>Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br><div><br></div>Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMak<wbr>e_FAQ</a><br><div><br></div>Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br><div><br></div>CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/su<wbr>pport.html</a><br> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/co<wbr>nsulting.html</a><br> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/tr<wbr>aining.html</a><br><div><br></div>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensou<wbr>rce/opensource.html</a><br><div><br></div>Follow this link to subscribe/unsubscribe:<br><a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/list<wbr>info/cmake</a><br></blockquote></div></div></blockquote><div><br></div></div></div></blockquote></div></div></blockquote><div><br></div></div></div></div></div></blockquote></div><br></div>
</div></div></blockquote><div><br></div></div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>