Normal Linux build produces executable without RPATH info
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.)
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.
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.
Note that ldconfig only helps if the program is installed in a system location, like /usr/local/lib/. (And this requires root access, naturally.)