intel / collision-avoidance-library

A framework for testing and benchmarking collision avoidance strategies
Apache License 2.0
81 stars 39 forks source link

Library runpaths not set on install #131

Closed fnoop closed 7 years ago

fnoop commented 7 years ago

If I compile like this: /usr/bin/cmake .. -DCMAKE_PREFIX_PATH=/srv/maverick/software/librealsense -DCMAKE_INSTALL_PREFIX=/srv/maverick/software/collision_avoidance -DWITH_REALSENSE=ON -DWITH_TOOLS=ON -DWITH_SAMPLES=ON && make && make install Then the compile and install goes fine. The relevent libraries are found and linked in correctly at the build stage:

[dev] [mav@maverick-joule ~/var/build/collision_avoidance/build]$ ldd libcoav.so.0.0.1
    linux-vdso.so.1 =>  (0x00007ffcf09be000)
    librealsense.so.1 => /srv/maverick/software/librealsense/lib/librealsense.so.1 (0x00007fa522ba9000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa5227e4000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa5224db000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa5222c5000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa5220a7000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa521cde000)
    libusb-1.0.so.0 => /lib/x86_64-linux-gnu/libusb-1.0.so.0 (0x00007fa521ac6000)
    /lib64/ld-linux-x86-64.so.2 (0x000056367a3d7000)
    libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007fa521aa5000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa52189d000)
[dev] [mav@maverick-joule ~/var/build/collision_avoidance/build]$ ldd tools/coav-control/coav-control
    linux-vdso.so.1 =>  (0x00007ffd8137c000)
    libcoav.so.0 => /srv/maverick/var/build/collision_avoidance/build/libcoav.so.0 (0x00007fb39c29a000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb39bed5000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb39bcbf000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb39baa2000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb39b6d8000)
    librealsense.so.1 => /srv/maverick/software/librealsense/lib/librealsense.so.1 (0x00007fb39b3da000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb39b0d1000)
    /lib64/ld-linux-x86-64.so.2 (0x00005606da17d000)
    libusb-1.0.so.0 => /lib/x86_64-linux-gnu/libusb-1.0.so.0 (0x00007fb39aeb8000)
    libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007fb39ae98000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb39ac8f000)

However, when installed the rpaths are not set so there are missing libraries:

[dev] [mav@maverick-joule ~/software/collision_avoidance]$ ldd bin/coav-control
    linux-vdso.so.1 =>  (0x00007ffe08f24000)
    libcoav.so.0 => not found
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f6658dea000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f6658bd3000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f66589b6000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f66585ed000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f66582e3000)
    /lib64/ld-linux-x86-64.so.2 (0x000056208ea24000)
[dev] [mav@maverick-joule ~/software/collision_avoidance]$ ldd lib/libcoav.so.0.0.1
    linux-vdso.so.1 =>  (0x00007fff2b9ed000)
    librealsense.so.1 => not found
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f23ac492000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f23ac188000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f23abf72000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f23abd55000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f23ab98b000)
    /lib64/ld-linux-x86-64.so.2 (0x000055a3a9289000)
fnoop commented 7 years ago

Adding -DCMAKE_INSTALL_RPATH=/srv/maverick/software/librealsense/lib:/srv/maverick/software/collision_avoidance/lib to cmake line makes it work for me, but this should be set automatically I think.

mbelluzzo commented 7 years ago

I think that the behavior of either CMAKE_PREFIX_PATH and CMAKE_INSTALL_PREFIX are working as expected.

Cmake will only use rpath after installation when explicit told to do it (like when you set CMAKE_INSTALL_RPATH) because it doesn't always make sense to use it. Imagine that I have my drone dependencies on my host machine in a custom path and I'm compiling against it and, after installing on the drone, those will be on totally different places (probably on the default path on the drone), so the paths may not even exist on the final target.

Also, to have those path's hardcoded on the binary isn't very robust, so usually is preferred that you tell ld.so to look on extra paths before running (with LD_LIBRARY_PATH) if you know that you have objects installed on non-default paths instead of recording those paths on the binary.

fnoop commented 7 years ago

LD_LIBRARY_PATH is generally frowned upon - setting library paths in ldconfig is OK so in the case of librealsense that would make sense. However, the coav-tool should surely be able to find it's own library without extra help?

mbelluzzo commented 7 years ago

libcoav is just like any other dependency from the POV of coav-control once is installed. ld.so should be able to find just like any other library.