waifu2x-converter-cpp icon indicating copy to clipboard operation
waifu2x-converter-cpp copied to clipboard

Normal Linux build produces executable without RPATH info

Open iskunk opened this issue 5 years ago • 3 comments

I am able to build the project successfully on Linux, using e.g.

$ cmake -DCMAKE_INSTALL_PREFIX=/tmp/WAIFU2X /path/to/waifu2x-converter-cpp-source

However, after the make and make install, when I go to run the program, I get this:

$ /tmp/WAIFU2X/bin/waifu2x-converter-cpp --help
/tmp/WAIFU2X/bin/waifu2x-converter-cpp: error while loading shared libraries: libw2xc.so: cannot open shared object file: No such file or directory

It only runs correctly if I set LD_LIBRARY_PATH=/tmp/WAIFU2X/lib in the environment, which is annoying.

I'd like to suggest a minor change, which will cause the project's built binaries to have a relative RPATH setting that allows them to work cleanly in the above scenario:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a13b35d..5036a65 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -83,6 +83,7 @@ elseif(UNIX OR MINGW)
        if (NOT FILE_SYSTEM_LIB AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
                set(FILE_SYSTEM_LIB "stdc++fs")
        endif()
+       set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib${LIB_SUFFIX}")
 elseif(MSVC)
        include(CheckCXXCompilerFlag)
        CHECK_CXX_COMPILER_FLAG("/std:c++latest" have_std_cpp_latest)

(There may be a better place to put this setting, as it is only applicable to UNIX builds.)

iskunk avatar Jun 19 '20 08:06 iskunk

I can confirm I get the same error after installing. By default libw2xc.so gets installed to /usr/local/lib but the program looks for it in /usr/lib, hence the file not found error. A workaround is moving libw2xc.so from /usr/local/lib to /usr/lib, or create a symlink.

vercingetorx avatar Jul 11 '20 17:07 vercingetorx

I had the same issue after sudo make install

> waifu2x-converter-cpp --help
waifu2x-converter-cpp: error while loading shared libraries: libw2xc.so: cannot open shared object file: No such file or directory

So I did

sudo ldconfig

as suggested in BUILDING.md Then waifu2x-converter-cpp --help worked as expected.

NikolayXHD avatar May 05 '21 02:05 NikolayXHD

Note that ldconfig only helps if the program is installed in a system location, like /usr/local/lib/. (And this requires root access, naturally.)

iskunk avatar May 05 '21 04:05 iskunk