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.
- Added the
"PKG_BUILD_FLAGS := no-strip"in the openwrt makefile and not working. - 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?