0

I am working on OpenWrt 23.05, to run a CGI script from the browser URL e.g. http://192.168.1.1/cgi-bin/myapp.cgi The server is uHTTPd. My CGI file is written in C++ that needs no interpreter. The CGI file depends on some libraries that are present in /opt/lib/ folder and not in the /usr/lib folder.

In the CGI makefile added the rpath -Wl, rpath=/opt/lib/. With this change, the CGI runs and passes all the cases when the binary is copied to the target device (/www/cgi-bin) folder. However when I install the .ipk or copy the CGI file present in the .ipk file, it doesn't work. Looks like the symbols and RPATH are stripped from the ipk binary.

I have tried the following as suggested by ChatGPT/Gemini but none working.

  1. Added the "PKG_BUILD_FLAGS := no-strip" in the openwrt makefile and not working.
  2. Added the option cgi_env 'LD_LIBRARY_PATH=/opt/lib' - I doubt it is a valid uHTTPd UCI setting

Here is the error snippet,

export LD_LIBRARY_PATH=
~ # ldd /www/cgi-bin/myapp.cgi
        libpcre.so.1 => /usr/lib/libpcre.so.1 (0x7f99f29000)
        libpcrecpp.so.0 => /usr/lib/libpcrecpp.so.0 (0x7f99f08000)
        libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0x7f99d43000)
        libcgicc.so.3 => /usr/lib/libcgicc.so.3 (0x7f99d12000)
        libctpp2.so.2 => /usr/lib/libctpp2.so.2 (0x7f99c71000)
Error loading shared library libmgr.so: No such file or directory (needed by /www/cgi-bin/myapp.cgi)

libmgr.so - is my custom library present in /opt/lib

It also suggest to run the CGI file inside a script (.sh) file and provide the library path before execution. I believe it works but I don't want a script in-between.

Any suggestions in fixing this?

1 Answer 1

0

Here's what I would suggest to make the LD_LIBRARY_PATH change permanent on OpenWRT.

  1. Edit /etc/ld.so.conf. Add a line to it, with the path of the directory holding the library.

    /opt/lib

  2. Run ldconfig as root. This will re-build the /etc/ld.so.cache file, which should add your new file to the index.

  3. If you need to add more files to the /opt/lib directory, you will need to re-run ldconfig.

Source: The "Setup library search paths using ld.so.conf" section of this page from the OpenWRT wiki.

Note: I have not tested the preceding suggestion.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.