Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Normal Linux build produces executable without RPATH info #249

Open
iskunk opened this issue Jun 19, 2020 · 3 comments
Open

Normal Linux build produces executable without RPATH info #249

iskunk opened this issue Jun 19, 2020 · 3 comments

Comments

@iskunk
Copy link

iskunk commented Jun 19, 2020

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.)

@vercingetorx
Copy link

vercingetorx commented Jul 11, 2020

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.

@NikolayXHD
Copy link

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.

@iskunk
Copy link
Author

iskunk commented May 5, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants