On 2018 M01 4, Thu 10:06:26 CET Franck Houssen wrote: ... > ... > target_include_directories(main PUBLIC ${PETSc_INCLUDE_DIRS}) > foreach(lib ${PETSc_LDFLAGS}) > target_link_libraries(main PUBLIC ${lib}) > message("target_link_libraries - lib is ${lib}") > endforeach(lib) > > foreach(dir ${PETSc_LIBRARY_DIRS}) > link_directories(main PUBLIC ${dir}) # Not sure: is this needed ? > message("link_directories - dir is ${dir}") > endforeach(dir) > > This gives: > >> cmake ..; make > > ... > target_link_libraries - lib is -L/path/to/petsc/local/lib > target_link_libraries - lib is -lpetsc > link_directories - dir is /path/to/petsc/local/lib
yes, so cmake doesn't know that it will link to /path/to/petsc/local/lib/ libpetsc.so . I usually recommend to use the results from pkgconfig as input to find_library() etc. calls, ie. put the directory reported by pkgconfig in the HINTS section of find_library(). This should then return the full path to the library, which you can then use in target_link_libraries(), and cmake will take care of the rpath. ... > >> ldd main > > linux-vdso.so.1 (0x00007ffebab8a000) > libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20 > (0x00007f36172e3000) libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20 > (0x00007f3616fed000) libpetsc.so.3.8 => not found you can also use readelf or objdump to see the RPATH entry in the ELF file directly. Alex -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake