<html><body><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div>Working !... At last ! Thanks :D<br></div><div><br></div><div>I suspected an ordering problem: I already tried to change the position of "setting CMAKE_INSTALL_RPATH" before / after "calling target_link_libraries"... But didn't try to do this BEFORE add_executable !<br></div><div><br></div><div>Would be nice to add this in the doc <a href="https://cmake.org/Wiki/CMake_RPATH_handling">https://cmake.org/Wiki/CMake_RPATH_handling</a> : can somebody do that or should I post that to the dev-mail list ?!...<br></div><div><br></div><div>Anyway, thanks guys<br></div><div><br></div><div>Franck<br></div><div><br></div><hr id="zwchr"><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;" data-mce-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" <hintonda@gmail.com><br><b>À: </b>"Franck Houssen" <franck.houssen@inria.fr><br><b>Cc: </b>"Andreas Naumann" <Andreas-Naumann@gmx.net>, "CMake Mail List" <cmake@cmake.org><br><b>Envoyé: </b>Jeudi 4 Janvier 2018 21:49:05<br><b>Objet: </b>Re: [CMake] RPATH for pkg-config<br><div><br></div><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><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>$ 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>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/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>$ 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>hth...</div><div>don</div></div></div><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" data-mce-href="mailto:franck.houssen@inria.fr">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" data-mce-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" data-mce-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 class=""><span class="">cmake_minimum_required(VERSION 3.7)<br>enable_language(CXX)<br></span></span><div><br></div><span class=""><span class="">find_package(MPI REQUIRED)<br>find_package(PkgConfig REQUIRED) # Get pkg_check_modules.<br>pkg_check_modules(PETSc REQUIRED PETSc)<br></span></span><div><br></div><span class=""><span class="">project(main)<br>add_executable(main main.cpp)<br></span></span><div><br></div><span class=""><span class="">target_include_directories(main PUBLIC ${MPI_CXX_INCLUDE_PATH})<br>target_link_libraries(main PUBLIC ${MPI_CXX_LIBRARIES})<br></span></span><div><br></div><span class="">target_include_directories(main PUBLIC ${PETSc_INCLUDE_DIRS})<br>foreach(lib ${PETSc_LDFLAGS})<br> target_link_libraries(main PUBLIC ${lib})<br></span><span class=""><span class=""> message("target_link_libraries - lib is ${lib}")<br>endforeach(lib)<br></span></span><div><br></div><span class=""># 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_RPATH TRUE)<br>SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_RPATH}")<span class=""><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_LINK_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_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)<br></span><span class="">IF("${isSystemDir}" STREQUAL "-1")<br></span> SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_RPATH}")<span class=""><br>ENDIF("${isSystemDir}" STREQUAL "-1")<br></span><span class="">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}")<br>endforeach(dir)<br></span>message("CMAKE_INSTALL_RPATH: ${CMAKE_INSTALL_RPATH}")<span class=""><span class=""><br></span></span><div><br></div><span class="">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_-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" data-mce-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 class=""><b>De: </b>"Don Hinton" <<a href="mailto:hintonda@gmail.com" target="_blank" data-mce-href="mailto:hintonda@gmail.com">hintonda@gmail.com</a>><br><b>À: </b>"Franck Houssen" <<a href="mailto:franck.houssen@inria.fr" target="_blank" data-mce-href="mailto:franck.houssen@inria.fr">franck.houssen@inria.fr</a>><br></span><b>Cc: </b>"Andreas Naumann" <<a href="mailto:Andreas-Naumann@gmx.net" target="_blank" data-mce-href="mailto:Andreas-Naumann@gmx.net">Andreas-Naumann@gmx.net</a>>, "CMake Mail List" <<a href="mailto:cmake@cmake.org" target="_blank" data-mce-href="mailto:cmake@cmake.org">cmake@cmake.org</a>><br><b>Envoyé: </b>Jeudi 4 Janvier 2018 17:47:19<div><div class="h5"><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" data-mce-style="color: #000000; 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" data-mce-style="color: #000000; 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" data-mce-style="color: #000000; 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" data-mce-style="color: #000000; 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" data-mce-style="color: #000000; 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" data-mce-style="color: #000000; 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" data-mce-style="color: #000000; 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" data-mce-href="mailto:franck.houssen@inria.fr">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" data-mce-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" data-mce-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_-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" data-mce-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" data-mce-href="mailto:hintonda@gmail.com">hintonda@gmail.com</a>><br><b>À: </b>"Franck Houssen" <<a href="mailto:franck.houssen@inria.fr" target="_blank" data-mce-href="mailto:franck.houssen@inria.fr">franck.houssen@inria.fr</a>><br><b>Cc: </b>"Andreas Naumann" <<a href="mailto:Andreas-Naumann@gmx.net" target="_blank" data-mce-href="mailto:Andreas-Naumann@gmx.net">Andreas-Naumann@gmx.net</a>>, <a href="mailto:cmake@cmake.org" target="_blank" data-mce-href="mailto:cmake@cmake.org">cmake@cmake.org</a><br></span><b>Envoyé: </b>Jeudi 4 Janvier 2018 16:52:53<span><span><br><b>Objet: </b>Re: [CMake] RPATH for pkg-config<br></span></span><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" data-mce-href="mailto:franck.houssen@inria.fr">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" data-mce-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" data-mce-style="font-family: times new roman,new york,times,serif; font-size: 12pt; color: #000000;"><hr id="m_-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" data-mce-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" data-mce-href="mailto:hintonda@gmail.com">hintonda@gmail.com</a>><br><b>À: </b>"Franck Houssen" <<a href="mailto:franck.houssen@inria.fr" target="_blank" data-mce-href="mailto:franck.houssen@inria.fr">franck.houssen@inria.fr</a>><br><b>Cc: </b>"Andreas Naumann" <<a href="mailto:Andreas-Naumann@gmx.net" target="_blank" data-mce-href="mailto:Andreas-Naumann@gmx.net">Andreas-Naumann@gmx.net</a>>, <a href="mailto:cmake@cmake.org" target="_blank" data-mce-href="mailto:cmake@cmake.org">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" data-mce-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" data-mce-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" data-mce-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" data-mce-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" data-mce-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=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" data-mce-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" data-mce-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}")<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" data-mce-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" data-mce-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></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><div><br></div><div>>> cmake ..; make VERBOSE=1<br>...<br></div><div><span>target_link_libraries - lib is -L/home/fghoussen/Documents/INRIA/petsc/local/lib<br>target_link_libraries - lib is -lpetsc<br>link_directories - dir is /home/fghoussen/Documents/INRIA/petsc/local/lib<br></span>CMAKE_INSTALL_RPATH: /home/fghoussen/Documents/INRIA/petsc/local/lib;/usr/local/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/libmpi_cxx.so.20 (0x00007f429a28a000)<br> libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20 (0x00007f4299f94000)<br> libpetsc.so.3.8 => not found<br><div><br></div></div><div><div class="m_-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" data-mce-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" data-mce-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" data-mce-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" data-mce-style="font-family: times new roman,new york,times,serif; font-size: 12pt; color: #000000;"><div>...</div><div>SET(CMAKE_BUILD_WITH_INSTALL_RPATH 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" data-mce-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/INRIA/petsc/local/lib<br>target_link_libraries - lib is -lpetsc<br>link_directories - dir is /home/fghoussen/Documents/INRIA/petsc/local/lib</div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000" data-mce-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/openmpi/include/openmpi -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/opal/mca/event/libevent2022/libevent -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/opal/mca/event/libevent2022/libevent/include -I/usr/lib/x86_64-linux-gnu/openmpi/include -I/home/fghoussen/Documents/INRIA/petsc/local/include -o CMakeFiles/main.dir/main.cpp.o -c /home/fghoussen/Downloads/cmake/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 -o main -Wl,-rpath,/usr/lib/x86_64-linux-gnu/openmpi/lib /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so -L/home/fghoussen/Documents/INRIA/petsc/local/lib -lpetsc <br>make[2]: Leaving directory '/home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD'<br>[100%] Built target main<br>make[1]: Leaving directory '/home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD'<br>/usr/bin/cmake -E cmake_progress_start /home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD/CMakeFiles 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/libmpi_cxx.so.20 (0x00007f9eaba1f000)<br> libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.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" data-mce-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" data-mce-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" data-mce-href="mailto:franck.houssen@inria.fr">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" data-mce-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" data-mce-href="mailto:Andreas-Naumann@gmx.net">Andreas-Naumann@gmx.net</a>><br> > À: <a href="mailto:cmake@cmake.org" target="_blank" data-mce-href="mailto:cmake@cmake.org">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" data-mce-href="http://jacobmerson.com/2016/01/17/cmake-petsc2.html">http://jacobmerson.com/2016/01/17/cmake-petsc2.html</a><br> > *<a href="http://www.mcs.anl.gov/petsc/documentation/faq.html#cmake" rel="noreferrer" target="_blank" data-mce-href="http://www.mcs.anl.gov/petsc/documentation/faq.html#cmake">http://www.mcs.anl.gov/petsc/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" data-mce-href="https://cmake.org/Wiki/CMake_RPATH_handling">https://cmake.org/Wiki/CMake_RPATH_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(main PUBLIC ${MPI_CXX_INCLUDE_PATH})<br> > >> target_link_libraries(main PUBLIC ${MPI_CXX_LIBRARIES})<br> > >><br> > >> target_include_directories(main 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_RPATH 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" data-mce-href="http://www.kitware.com">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" data-mce-href="http://www.cmake.org/Wiki/CMake_FAQ">http://www.cmake.org/Wiki/CMake_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" data-mce-href="http://cmake.org/cmake/help/support.html">http://cmake.org/cmake/help/support.html</a><br> > CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank" data-mce-href="http://cmake.org/cmake/help/consulting.html">http://cmake.org/cmake/help/consulting.html</a><br> > CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank" data-mce-href="http://cmake.org/cmake/help/training.html">http://cmake.org/cmake/help/training.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" data-mce-href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br> ><br> > Follow this link to subscribe/unsubscribe:<br> > <a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank" data-mce-href="https://cmake.org/mailman/listinfo/cmake">https://cmake.org/mailman/listinfo/cmake</a><br> ><br> --<br><div><br></div>Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank" data-mce-href="http://www.kitware.com">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" data-mce-href="http://www.cmake.org/Wiki/CMake_FAQ">http://www.cmake.org/Wiki/CMake_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" data-mce-href="http://cmake.org/cmake/help/support.html">http://cmake.org/cmake/help/support.html</a><br> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank" data-mce-href="http://cmake.org/cmake/help/consulting.html">http://cmake.org/cmake/help/consulting.html</a><br> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank" data-mce-href="http://cmake.org/cmake/help/training.html">http://cmake.org/cmake/help/training.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" data-mce-href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/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" data-mce-href="https://cmake.org/mailman/listinfo/cmake">https://cmake.org/mailman/listinfo/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></blockquote><div><br></div></div></body></html>